[DevExpress]skin窗体换肤
转自:http://www.evget.com/article/2014/10/10/21667.html
最近在学习 DevExpress 这个控件,将窗体换肤的一些心得记录下来,分享给大家:
【DXperience Universal Suite下载】
1.添加引用:
2.在ribbonPageGroup下新建个ribbonGalleryBarItem,并添加GalleryItemClick 事件:ribbonGalleryBarItem1_GalleryItemClick:
3.在应用程序的主入口里添加:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
DevExpress.UserSkins.BonusSkins.Register();
DevExpress.Skins.SkinManager.EnableFormSkins();
DevExpress.Skins.SkinManager.EnableMdiFormSkins();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new Form1());
}
}
|
4.在窗体代码里添加命名空间using System.Xml;在事件ribbonGalleryBarItem1_Click里添加代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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" );
}
|
5.添加命名空间using DevExpress.XtraBars.Helpers和using DevExpress.LookAndFeel;在Load下添加代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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
|
6.效果:
备注:win 7 以上版本经常允许透明的标题栏,同样选择的皮肤部分的变成透明。
只需要设置AllowFormGlass为false即可。
[DevExpress]skin窗体换肤相关推荐
- SkinSharp(Skin#)软件换肤库!
SkinSharp又称Skin#,是Windows环境下一款强大的换肤组件. SkinSharp作为换肤控件,只需要在您的程序中添加一行代码,就能让您的界面焕然一新,并拥有多种主题风格和色调的动态切换 ...
- DevExpress 换肤
在devexpress中,换肤就很简单,不需要我们自己去制造皮肤,官文就有很丰富的皮肤包.下面来讲解一下这个问题. 注意,我这儿用的是DevExpress 8.1.5,在老版本中可能不支持.如果是7. ...
- vue+scss实现一键换肤
大概的思路就是给html根标签设置一个data-theme属性,然后通过js切换data-theme的属性值,Scss根据此属性来判断使用对应主题变量.这里可以选择持久化Vux配合存储属性或接口来保存 ...
- devexpress java_DevExpress使用心得一:换肤
最近要用到界面控件DevExpress.一句话:很好很强大,比起VS自带的winform界面,种类和花样要多了不少.然而,强力的功能带来了庞大的信息量,所以我打算通过一些小模块来和大家一起对它进行探讨 ...
- C# Winform 窗体美化(一、IrisSkin 换肤库)
IrisSkin 换肤库 IrisSkin 是为Microsoft Visual Studio dotNET开发的最易用的界面增强dotNET(WinForm)组件包.能完全自动的为应用程序添加支持换 ...
- Leakcanary原理解析以及换肤框架skin的原理分析
一.错误现场 java.lang.ClassCastException: androidx.appcompat.widget.TintContextWrapper cannot be cast to ...
- c语言中用qt写换肤,让Qt应用程序支持换肤(Skin)功能
Qt程序一直给人的印象是正规的GUI程序的模样.在嵌入式Linux下,Qtopia的桌面看起来跟WinCE桌面没有什么两样.相对IPHONE那样的漂亮界面.实在没有什么吸引力. 因此很多嵌入式开发人员 ...
- 仿酷狗音乐播放器开发日志十八——换肤功能的实现二:改变控件和窗体透明度(附挂件类源码)...
转载请说明原出处,谢谢~~ 昨天把大致布局分析了一下,昨天晚上把布局写好实现了,今天把大致的功能完成了一下,现在的外观已经和原酷狗的换肤界面完全一样,其中的调整播放列表透明度和设置整个软件透明度的代码 ...
- 仿酷狗音乐播放器开发日志十八——换肤功能的实现二:改变控件和窗体透明度(附挂件类源码)
转载请说明原出处,谢谢~~ 昨天把大致布局分析了一下,昨天晚上把布局写好实现了,今天把大致的功能完成了一下,现在的外观已经和原酷狗的换肤界面完全一样,其中的调整播放列表透明度和设置整个软件透明度的代码 ...
最新文章
- Facebook开源最大规模并行语料,45亿语料,覆盖576种语言对
- 双系统 win10 时间不对
- 一图简述大数据技术生态圈
- 【Linux学习篇】This virtual machine is configured for 64-bit guest operating systems.……
- java接口作用和好处,持续更新大厂面试笔试题
- Silverlight 3.0 Isolated Storage 独立存储空间
- [bzoj1355][Baltic2009]Radio Transmission_KMP
- 实践案例丨Pt-osc工具连接rds for mysql 数据库失败
- (转)如何在MySql中记录SQL日志(例如Sql Server Profiler)
- 2017.4找工作面试记录-第三周(2)--金蝶
- select函数的使用
- Unity游戏接入Steam成就
- 一文读懂方向导数与梯度
- compute的c语言用法,词汇精选:compute的用法和辨析
- java计算某天到当前时间的间隔天数
- AWS免费账号取消步骤
- C语言学生管理系统(期末作业,超详细哟,拿走不谢!!!)
- 微信小程序60秒倒计时
- 幂等性问题以及处理方法
- elementui table 表格固定列最后一行显示不全