Skins

打印 上一主题 下一主题

主题 541|帖子 541|积分 1623

本主题表明如何将DevExpress主题/皮肤应用到应用步伐中,如何答应用户在运行时在主题之间切换,如何自界说现有皮肤或创建本身的皮肤,等等。
WinForms订阅包括很多基本控件:按钮、复选框、表单、消息框、对话框、对话框等。
我们实现全部这些控件的一个紧张缘故原由是为了支持我们的主题。通过
的开发表达,您可以获得各种各样的表面和一个全面的控制库,以保证整个应用步伐的可视化划一性。
要检察可用的主题/皮肤,请打开任何演示应用步伐
How to Apply a Skin

Design Time

打开“项目设置”页面,并选择所需的WinForms主题。此页面在中不可用。网络的焦点项目。将默认表面和感觉组件放在表单上,并使用其智能标签菜单,或在代码中指定所需的皮肤。
Runtime (In Code)

Call the UserLookAndFeel.SetSkinStyle method
  1. using DevExpress.LookAndFeel;
  2. // ...
  3. UserLookAndFeel.Default.SetSkinStyle(SkinStyle.WXI);
复制代码
How to Enable Bonus or Custom Skins

DevExpress皮肤紧张分为两大类:Devess推荐的最新皮肤和存储在单独的库/包中的过期/主题皮肤。


  • 当您使用模板库创建项目或将任何控件放到表单上时,现代皮肤立即可用。如果您开始了一个空白项目,则必要添加开发表达。手动使用工具库(或安装DevExpress.Utils NuGet package)。为空白。NET焦点(.NET 5)项目,安装DevExpress.Win.Design package.。
  • Outdated and thematic skins are stored in the DevExpress.BonusSkins library/NuGet package. These skins must be registered before you can apply them. To register bonus skins, check the corresponding setting on the Project Settings Page, or call the Register method on application startup:
  1. namespace WindowsFormsApplication1 {
  2.     static class Program {
  3.         [STAThread]
  4.         static void Main() {
  5.             DevExpress.UserSkins.BonusSkins.Register();
  6.             Application.EnableVisualStyles();
  7.             Application.SetCompatibleTextRenderingDefault(false);
  8.             Application.Run(new Form1());
  9.         }
  10.     }
  11. }
复制代码
After bonus skins are registered, you can apply them in the same manner you apply standard skins.
  1. using DevExpress.LookAndFeel;
  2. UserLookAndFeel.Default.SetSkinStyle(SkinStyle.Pumpkin);
复制代码
How to Let Users Select Skins at Runtime

DevExpress WinForms订阅包括多个现成的栏项,答应您的用户在皮肤和皮肤调色板之间切换。您可以将这些项目添加到“工具栏窗体”和“流畅计划窗体”的工具栏、功能区和标题栏中。

下面的代码将皮肤图库选择器添加到“ribbonPageGroup2”组中。
  1. using DevExpress.XtraBars;
  2. // ...
  3. SkinRibbonGalleryBarItem skinGallery = new SkinRibbonGalleryBarItem();
  4. ribbonPageGroup2.ItemLinks.Add(skinGallery);
复制代码
留意,如果您在代码中创建了下拉下载按钮项选择器,您必要调用初始下拉下载图片库方法来初始化此选择器的下拉列表。
  1. using DevExpress.XtraBars;
  2. using DevExpress.XtraBars.Helpers;
  3. // Add the selector next to the standard "Close", "Maximize", and "Minimize"
  4. // buttons of the Toolbar Form
  5. SkinDropDownButtonItem skinSelector = new SkinDropDownButtonItem();
  6. SkinHelper.InitDropDownSkinGallery(skinSelector);
  7. skinSelector.Alignment = BarItemLinkAlignment.Right;
  8. this.toolbarFormControl1.TitleItemLinks.Add(skinSelector);
复制代码
若要重命名和/或更改这些标准皮肤选择器的项的图标,请处理皮肤资助步伐。创建SkinHelper.CreateGalleryItem 变乱。
  1. using DevExpress.XtraBars;
  2. using DevExpress.XtraBars.Helpers;
  3. SkinHelper.CreateGalleryItem += (s, e) => {
  4.     if (e.ItemName.Equals("DevExpress Style")) {
  5.         e.GalleryItem.Image = e.UseLargeIcons ? MyCustomLargeIcon : MyCustomSmallIcon;
  6.         e.GalleryItem.HoverImage = MyCustomLargeIcon;
  7.         e.GalleryItem.Caption = "Moonlight";
  8.     }
  9. };
复制代码
How to: Add and Customize Toolbar Skin Selectors
How to: Add and Customize the Ribbon Skin List and Skin Gallery
How to: Build a Custom End-User Skin Selector
Skin Palettes

DevExpressWinForms皮肤可以在UI元素上绘制光栅或矢量图像。光栅蒙皮只有一个默认表面,而每个矢量蒙皮都附带一组选项板(样例)。用户可以选择调色板来修改当前皮肤的配色方案。下图体现了“Bezier”矢量皮肤附带的一些调色板。

可以使用与指定蒙皮雷同的方式应用调色板:打开“ Project Settings Page”页面或调用 SetSkinStyle(SkinSvgPalette)重载。
  1. using DevExpress.LookAndFeel;
  2. // ...
  3. UserLookAndFeel.Default.SetSkinStyle(SkinSvgPalette.Bezier.Tokyo);
复制代码
Default App Mode (Light/Dark)

使用Windows窗体设置。TrackWindowsAppMode设置,指定应用步伐在Windows操作体系中跟踪“默认应用步伐模式”设置,并在“skin gallery.”中仅体现浅色或深色调色板。
以下示例演示如何启用TrackWindowsAppMode 设置:
  1. static void Main() {
  2.     Application.EnableVisualStyles();
  3.     Application.SetCompatibleTextRenderingDefault(false);
  4.     WindowsFormsSettings.TrackWindowsAppMode = DevExpress.Utils.DefaultBoolean.True;
  5.     Application.Run(new Form1());
  6. }
复制代码
Highlight Individual Controls

突出体现单个控件
您可以为各个DevExpress控件(例如SimpleButtons)设置自界说背景、边框和远景色。要执行此操作,请从控件访问设置。表面组。发起您使用DX颜色而不是体系颜色:这些颜色是从皮肤中检索的,当用户在运行时更改皮肤时会自动更新。
  1. // Use DXSkinColors.FillColors for background colors
  2. simpleButton1.Appearance.BackColor = DXSkinColors.FillColors.Danger;
  3. // Use DXSkinColors.ForeColors for text colors
  4. simpleButton1.Appearance.ForeColor = DXSkinColors.ForeColors.Warning;
复制代码
Enable Skins for MDI Forms

启用MDI窗体的表面
在Program.Main()步伐中调用EnableMdiFormSkins()方法
  1. using System;
  2. using System.Windows.Forms;
  3. using DevExpress.XtraEditors;
  4. namespace DXApplication14 {
  5.     internal static class Program {
  6.         [STAThread]
  7.         static void Main() {
  8.             Application.EnableVisualStyles();
  9.             Application.SetCompatibleTextRenderingDefault(false);
  10.             WindowsFormsSettings.EnableMdiFormSkins();
  11.             Application.Run(new Form1());
  12.         }
  13.     }
  14. }
复制代码

Examples and Best Practices

示例和最佳实践


  • 如何获取当前活动皮肤和调色板的名称
    Read values of the ActiveSkinName and ActiveSvgPaletteName properties.
  1. var skinName = UserLookAndFeel.Default.ActiveSkinName;
  2. var paletteName = UserLookAndFeel.Default.ActiveSvgPaletteName;
复制代码


  • 如何识别在运行时更改的皮肤或调色板
    Handle the static UserLookAndFeel.StyleChanged event. This event raises every time a user applies a different skin or skin palette.
  1. UserLookAndFeel.Default.StyleChanged += (s, e) => {
  2.     // TODO
  3. };
复制代码


  • 如何在应用步伐重新启动时重新应用最后一个活动皮肤
    Windows窗体应用步伐设置功能答应您在客户端计算机上创建、存储和维护自界说应用步伐和用户首选项。当应用步伐重新启动时,您可以使用此功能保存和恢复活动皮肤和调色板。
    双击Visual Studio解决方案资源管理器中的“Settings.Settings”文件,然后创建两个String范例的条目。将两个条目的范围都设置为“用户”。当应用步伐即将关闭时,请保存UserLookAndFeel的值。违约皮肤名称和用户表面。违约ActiveSvgPaletteName属性设置为“应用步伐设置”。当应用步伐启动时,读取这些保存的值并将它们通报给UserLookAndFeel。SetSkinStyle方法作为参数。

  1. private void SkinSwitch_FormClosed(object sender, FormClosedEventArgs e)
  2.         {
  3.             var settings = Properties.Settings.Default;
  4.             settings.SkinName = UserLookAndFeel.Default.SkinName;
  5.             settings.Palette = UserLookAndFeel.Default.ActiveSvgPaletteName;
  6.             settings.CompactMode = UserLookAndFeel.Default.CompactUIModeForced;
  7.             settings.Save();
  8.         }
复制代码
  1. protected override void OnShown(EventArgs e) {
  2.     base.OnShown(e);
  3.     var settings = Properties.Settings.Default;
  4.     if (!string.IsNullOrEmpty(settings.SkinName)) {
  5.         if (settings.CompactMode)
  6.             UserLookAndFeel.ForceCompactUIMode(true, false);
  7.         if (!string.IsNullOrEmpty(settings.Palette))
  8.             UserLookAndFeel.Default.SetSkinStyle(settings.SkinName, settings.Palette);
  9.         else UserLookAndFeel.Default.SetSkinStyle(settings.SkinName, "DefaultSkinPalette");
  10.     }
  11. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

小秦哥

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表