ToB企服应用市场:ToB评测及商务社交产业平台

标题: Skins [打印本页]

作者: 小秦哥    时间: 2024-6-21 16:56
标题: Skins
本主题表明如何将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推荐的最新皮肤和存储在单独的库/包中的过期/主题皮肤。

  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

示例和最佳实践

  1. var skinName = UserLookAndFeel.Default.ActiveSkinName;
  2. var paletteName = UserLookAndFeel.Default.ActiveSvgPaletteName;
复制代码

  1. UserLookAndFeel.Default.StyleChanged += (s, e) => {
  2.     // TODO
  3. };
复制代码

  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企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4