相信很多朋友希望自己的软件可以非常漂亮,本文就简要介绍一下,对窗体换肤。
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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步