相信很多朋友希望自己的软件可以非常漂亮,本文就简要介绍一下,对窗体换肤。
1、在程序入口处,即Program.cs添加如下代码:
DevExpress.UserSkins.OfficeSkins.Register();
DevExpress.UserSkins.BonusSkins.Register();
2、所应用样式窗体需要继承自DevExpress.XtraEditors.XtraForm;
3、添加defaultLookAndFeel1控件;
4、在应用窗体调用如下代码:
#region 初始化皮肤
private void InitSkin()
{
BarSubItem bar = new BarSubItem();
bar.Caption = "皮肤设置";
bar.Name = "皮肤设置";
//迭代出所有皮肤样式
foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins)
{
BarButtonItem barBI = new BarButtonItem();
barBI.Tag = skin.SkinName;
barBI.Name = skin.SkinName;
barBI.Caption = skin.SkinName;
barBI.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(ItemClick);
this.barManager1.Items.AddRange(new DevExpress.XtraBars.BarItem[] { barBI });
bar.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] { new DevExpress.XtraBars.LinkPersistInfo(barBI) });
}
this.barManager1.Items.AddRange(new DevExpress.XtraBars.BarItem[] { bar });
this.barMenu.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] { new DevExpress.XtraBars.LinkPersistInfo(bar) });
}
#region 皮肤单击事件
private void ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
defaultLookAndFeel1.LookAndFeel.SetSkinStyle(e.Item.Tag.ToString());
e.Item.Hint = e.Item.Tag.ToString();
}
#endregion