DevExpress动态换肤
1.首先添加DevExpress.OfficeSkins和DevExpress.BonusSkins 两个引用。
在Main()函数之前进行皮肤注册:
1 static class Program 2 { 3 /// <summary> 4 /// 应用程序的主入口点。 5 /// </summary> 6 [STAThread] 7 static void Main() 8 { 9 DevExpress.UserSkins.BonusSkins.Register();//皮肤注册 10 DevExpress.UserSkins.OfficeSkins.Register(); 11 DevExpress.Skins.SkinManager.EnableFormSkins();//激活窗体皮肤,否则窗体还是操作系统默认主题风格 12 DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = "Blue"; 13 Application.EnableVisualStyles(); 14 Application.SetCompatibleTextRenderingDefault(false); 15 Application.Run(new XtraForm1()); 16 } 17 }
2.添加一个父窗体,加一个全局静态DefaultLookAndFeel 成员控制皮肤,其他所有的窗体都继承该父窗体。
public partial class frmBase: DevExpress.XtraEditors.XtraForm { private static DefaultLookAndFeel gLobalDefaultLookAndFeel = new DefaultLookAndFeel(); public static DefaultLookAndFeel GLobalDefaultLookAndFeel { get { return frmBase.gLobalDefaultLookAndFeel; } set { frmBase.gLobalDefaultLookAndFeel = value; } } public frmBase() { InitializeComponent(); } }
3.添加一个控制皮肤的窗体frmSkin:
public partial class frmSkin: DevExpress.XtraEditors.XtraForm { public frmSkin() { InitializeComponent(); } private void frmSkin_Load(object sender, EventArgs e) { foreach(DevExpress.Skins.SkinContainer skinc in DevExpress.Skins.SkinManager.Default.Skins) { cboSkins.Properties.Items.Add(skinc.SkinName); } } private void cboSkins_SelectedIndexChanged(object sender, EventArgs e) { frmBase.GLobalDefaultLookAndFeel.LookAndFeel.SkinName = cboSkins.Text; } private void btnOK_Click(object sender, EventArgs e) { this.Close(); } }