代码:
private UserLookAndFeel userLookAndFeel;
public MainGeneral()
{InitializeComponent();// 创建 UserLookAndFeel 实例userLookAndFeel = new UserLookAndFeel(this);// 订阅 StyleChanged 事件userLookAndFeel.StyleChanged += UserLookAndFeel_StyleChanged;
}
private void UserLookAndFeel_StyleChanged(object sender, EventArgs e)
{// 在这里处理样式变化事件// 弹出修改后皮肤的名字MessageBox.Show($"当前皮肤名字:{userLookAndFeel.ActiveSkinName} \n 当前皮肤是否是CompactUIModeForced:{userLookAndFeel.CompactUIModeForced} \n 当前皮肤配色名称:{userLookAndFeel.ActiveSvgPaletteName}");// 保存在app.config中,BaseDate.Instance.settings.Skin是我自定义的快速访问方法BaseDate.Instance.settings.Skin = $"{userLookAndFeel.ActiveSkinName},{userLookAndFeel.CompactUIModeForced},{userLookAndFeel.ActiveSvgPaletteName}";// 保存修改Settings.Default.Save();}
触发效果:
在Program中使用配置:
这两个内容是对应关系,我是直接通过settings文件来访问的配置
static void Main()
{// To customize application configuration such as set high DPI settings or default font,// see https://aka.ms/applicationconfiguration.ApplicationConfiguration.Initialize();string[] Skinlist = Properties.Settings.Default.Skin.Split(',');if (Skinlist.Length == 3){UserLookAndFeel.Default.SetSkinStyle(Skinlist[0], Skinlist[2]);if (Skinlist[1].ToLower().Equals("true")) {WindowsFormsSettings.CompactUIMode = DevExpress.Utils.DefaultBoolean.True;}}else{UserLookAndFeel.Default.SetSkinStyle(SkinStyle.WXICompact); // 设置默认皮肤主题}Application.Run(new Login());
}