DevExpress 窗体换肤
2020-12-13 05:42
标签:des style blog http color java os 文件 本文参考引用:http://www.cnblogs.com/dreamflycc/archive/2012/09/14/2685308.html 注意,如果控件已汉化,与上面参考的略有不同 1.添加引用: 4.在窗体代码里添加命名空间using System.Xml;在事件ribbonGalleryBarItem1_Click里添加代码: 5.添加命名空间using DevExpress.XtraBars.Helpers和using DevExpress.LookAndFeel;在Load下添加代码: 6.效果: DevExpress 窗体换肤,搜素材,soscw.com DevExpress 窗体换肤 标签:des style blog http color java os 文件 原文地址:http://www.cnblogs.com/huangzhenhua/p/3880244.html
static class Program
{
///
private void ribbonGalleryBarItem1_GalleryItemClick(object sender, DevExpress.XtraBars.Ribbon.GalleryItemClickEventArgs e)
{
string caption = string.Empty;
if (ribbonGalleryBarItem1.Gallery == null) return;
//caption = ribbonGalleryBarItem1.Gallery.GetCheckedItems()[0].Caption;
//上面那句会获取显示的名字,因为我已汉化,所以有中文,不能匹配UserLookAndFeel.Default.SetSkinStyle中的皮肤名称
//无法达到关闭后再加载关闭前的皮肤,如已汉化,参考下面这句:
caption = ribbonGalleryBarItem1.Gallery.GetCheckedItems()[0].Tag.ToString();//获取真实的名称,没有汉化的
caption = caption.Replace("主题:", "");
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");
} public string defaultSkinName;//皮肤
private void useSkin_Load(object sender, EventArgs e)
{
SkinHelper.InitSkinGallery(ribbonGalleryBarItem1);
CheckFile();//检查文件
GetXmlSkin();//获取xml主题
UserLookAndFeel.Default.SetSkinStyle(defaultSkinName);//设置主题样式
ribbonGalleryBarItem1.Caption = "主题:" + defaultSkinName;
}
#region 检查XML文件是否存在
public void CheckFile()
{
try
{
if (System.IO.File.Exists("SkinInfo.xml") == false)
{
//XtraMessageBox.Show("不存在XML");
CreateXml();
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#region 创建XML文件
public void CreateXml()
{
XmlDocument doc = new XmlDocument();
//建立xml定义声明
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(dec);
//创建根节点
XmlElement root = doc.CreateElement("SetSkin");
XmlElement rootone = doc.CreateElement("Skinstring");//皮肤
//将one,two,插入到root节点下
doc.AppendChild(root);
root.AppendChild(rootone);
doc.Save("SkinInfo.xml");
}
#endregion
#region 读取Xml节点内容
public void GetXmlSkin()
{
try
{
XmlDocument mydoc = new XmlDocument();
mydoc.Load("SkinInfo.xml");
XmlNode ressNode = mydoc.SelectSingleNode("SetSkin");
defaultSkinName = ressNode.SelectSingleNode("Skinstring").InnerText;
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion
#endregion
上一篇:实现MVC.NET 5的国际化
下一篇:C++中内联函数的用法