一、在项目下新建RibbonForm 命名为:useSkin
二、添加引用DevExpress.OfficeSkins
DevExpress.UserSkins.BonusSkins
DevExpress.UserSkins.BonusSkins
三、将ribbonPage1的Text属性设置为:皮肤
ribbonPageGroup1的Text属性设置为:更换皮肤
在ribbonPageGroup1下新建个ribbonGalleryBarItem1,将其Caption的属性设置为:请选择您喜欢的皮肤,并添GalleryItemClick 事件:ribbonGalleryBarItem1_GalleryItemClick
四、在应用程序的主入口里添加:
static void Main()
{
//皮肤
DevExpress.UserSkins.OfficeSkins.Register();
DevExpress.UserSkins.BonusSkins.Register();
DevExpress.Skins.SkinManager.EnableFormSkins();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Exercises.useSkin());
}
五、添加命名空间using System.Xml;
在事件ribbonGalleryBarItem1_Click里添加代码:
private void ribbonGalleryBarItem1_Click(object sender, DevExpress.XtraBars.Ribbon.GalleryItemClickEventArgs e)
{
string name = string.Empty;
string caption = string.Empty;
if (ribbonGalleryBarItem1.Gallery == null) return;
caption = ribbonGalleryBarItem1.Gallery.GetCheckedItems()[0].Caption;//主题的描述
caption = caption.Replace("主题:", "");
//name = bsiPaintStyle.Manager.PressedLink.Item.Tag.ToString();//主题的名称
ribbonGalleryBarItem1.Caption = "主题:" + caption;
XmlDocument doc = new XmlDocument();
doc.Load("SkinInfo.xml");
XmlNodeList nodelist = doc.SelectSingleNode("SetSkin").ChildNodes;
foreach (XmlNode node in nodelist)
{
XmlElement xe = (XmlElement)node;//将子节点类型转换为XmlElement类型
if (xe.Name == "Skinstring")
{
xe.InnerText = caption;
}
}
doc.Save("SkinInfo.xml");
//XtraMessageBox.Show("您选择了主题:" + caption);
}
添加命名空间
using DevExpress.XtraBars.Helpers;
using DevExpress.LookAndFeel;
六、添加命名空间using DevExpress.XtraEditors;
在Load下添加代码:
好了,现在就可以为自己的窗体选择喜欢的皮肤了。
看一下效果吧。。。。