DEV皮肤(系统默认和自定义皮肤调用)
基于DEV版本9.3.4.0,查看DEV控件的皮肤。
DEV控件提供了多种多样的皮肤样式,用户可以直接引用这些皮肤样式。也可以通过DEV提供的工具来制作自己喜欢的皮肤样式。
下面的实例程序比官方DEMO的实例程序缺少5中默认的皮肤样式,我自己没有找到,如果有人知道希望可以告诉我,谢谢!其实程序也用不到官方提供的那么多皮肤样式(因为里面有很多相似的或者挺难看的)我们只要根据自己需要添加几种即可,这里是实例程序,因此列出了大部分皮肤样式。
下面介绍一下自己编写的实例程序:
首先,搭建实例环境,如下图所示(本人使用VS2008和DEV9.3.4.0)
建立框架后除了必要的引用外要单独添加下面两个引用,第一个引用是调用DEV的额外皮肤所必须的,第二个引用是调用Office皮肤所必须的引用。
添加引用之后,我们要使用这些引用,首先要在程序开始时候进行注册,这个过程在Program.cs中进行完成。下面是类文件中的代码
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Windows.Forms;
5:
6: namespace DevSkin
7: {
8: static class Program
9: {
10: /// <summary>
11: /// 应用程序的主入口点。
12: /// </summary>
13: [STAThread]
14: static void Main()
15: {
16: DevExpress.UserSkins.BonusSkins.Register();//进行皮肤组件注册
17: DevExpress.UserSkins.OfficeSkins.Register();//进行皮肤组件注册
18: DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinProjectTest).Assembly); //Register!
19: Application.EnableVisualStyles();
20: Application.SetCompatibleTextRenderingDefault(false);
21: //Add
22: if (!DevExpress.Skins.SkinManager.AllowFormSkins)
23: {
24: DevExpress.Skins.SkinManager.EnableFormSkins();
25: }
26: Application.Run(new RibbonFrmMain());
27: }
28: }
29: }
下面是主窗体的全部代码,其中对于皮肤调用通过添加注释的方式进行说明。
注意:里面皮肤的中文名称大部分都是我自己起的名称,并没有查阅相关资料,如果觉得不合适可以自己修改哈。
1: using System;
2: using System.Collections;
3: using System.Collections.Generic;
4: using System.ComponentModel;
5: using System.Data;
6: using System.Drawing;
7: using System.Text;
8: using System.Windows.Forms;
9: using DevExpress.XtraBars;
10: using DevExpress.XtraBars.Ribbon;
11: using DevExpress.XtraBars.Ribbon.Gallery;
12: using DevExpress.XtraBars.Ribbon.Internal;
13: using DevExpress.XtraEditors;
14: using DevExpress.Skins;
15: using DevExpress.Utils.Drawing;
16:
17: namespace DevSkin
18: {
19: public partial class RibbonFrmMain : DevExpress.XtraBars.Ribbon.RibbonForm
20: {
21: public RibbonFrmMain()
22: {
23: InitializeComponent();
24: }
25:
26: private void RibbonFormMain_Load(object sender, EventArgs e)
27: {
28: //RibbonGalleryBarItem ribbonGalleryBarItem_Skin = new RibbonGalleryBarItem();
29: ribbonGalleryBarItem_Skin.Gallery.AllowHoverImages = true;
30: ribbonGalleryBarItem_Skin.Gallery.Appearance.ItemCaption.Options.UseFont = true;
31: ribbonGalleryBarItem_Skin.Gallery.Appearance.ItemCaption.Options.UseTextOptions = true;
32: ribbonGalleryBarItem_Skin.Gallery.Appearance.ItemCaption.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
33: ribbonGalleryBarItem_Skin.Gallery.ColumnCount = 4;
34: ribbonGalleryBarItem_Skin.Gallery.FixedHoverImageSize = false;
35: DevExpress.XtraBars.Ribbon.GalleryItemGroup galleryItemGroup_System = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
36: DevExpress.XtraBars.Ribbon.GalleryItemGroup galleryItemGroup_Office = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
37: DevExpress.XtraBars.Ribbon.GalleryItemGroup galleryItemGroup_Bonus = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
38:
39: galleryItemGroup_System.Caption = "系统皮肤";
40: galleryItemGroup_Office.Caption = "Office皮肤";
41: galleryItemGroup_Bonus.Caption = "附加风格";
42: ribbonGalleryBarItem_Skin.Gallery.Groups.AddRange(new DevExpress.XtraBars.Ribbon.GalleryItemGroup[] { galleryItemGroup_System, galleryItemGroup_Office, galleryItemGroup_Bonus });
43: ribbonGalleryBarItem_Skin.Gallery.ImageSize = new System.Drawing.Size(32, 17);
44: ribbonGalleryBarItem_Skin.Gallery.ItemImageLocation = DevExpress.Utils.Locations.Top;
45: ribbonGalleryBarItem_Skin.Gallery.RowCount = 4;
46: ribbonGalleryBarItem_Skin.Gallery.InitDropDownGallery += new DevExpress.XtraBars.Ribbon.InplaceGalleryEventHandler(rgbiSkins_Gallery_InitDropDownGallery);
47: ribbonGalleryBarItem_Skin.Gallery.ItemClick += new DevExpress.XtraBars.Ribbon.GalleryItemClickEventHandler(rgbiSkins_Gallery_ItemClick);
48: ribbonGalleryBarItem_Skin.Name = "ribbonGalleryBarItem_Skin";
49: //ribbonPageGroup_Skin.ItemLinks.Add(ribbonGalleryBarItem_Skin);
50: InitSkinGallery(ribbonGalleryBarItem_Skin);
51: }
52:
53: #region 皮肤
54:
55: private void rgbiSkins_Gallery_ItemClick(object sender, DevExpress.XtraBars.Ribbon.GalleryItemClickEventArgs e)
56: {
57: DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(e.Item.Tag.ToString());
58: }
59: private void rgbiSkins_Gallery_InitDropDownGallery(object sender, DevExpress.XtraBars.Ribbon.InplaceGalleryEventArgs e)
60: {
61: e.PopupGallery.CreateFrom((sender as DevExpress.XtraBars.Ribbon.Gallery.InRibbonGallery).OwnerItem.Gallery);
62: e.PopupGallery.AllowFilter = false;
63: e.PopupGallery.ShowItemText = true;
64: e.PopupGallery.ShowGroupCaption = true;
65: e.PopupGallery.AllowHoverImages = false;
66: foreach (GalleryItemGroup galleryGroup in e.PopupGallery.Groups)
67: foreach (GalleryItem item in galleryGroup.Items)
68: item.Image = item.HoverImage;
69: e.PopupGallery.ColumnCount = 2;
70: e.PopupGallery.ImageSize = new Size(70, 36);
71: }
72: private void InitSkinGallery(RibbonGalleryBarItem rgbiSkins)
73: {
74: Hashtable skinName = new Hashtable();
75: //系统风格 系统默认
76: skinName.Add("SystemDev Caramel", "焦糖");
77: skinName.Add("SystemDev Money Twins", "潮汐");
78: skinName.Add("SystemDev Lilian", "莉莲");
79: skinName.Add("SystemDev The Asphalt World", "柏油");
80: skinName.Add("SystemDev iMaginary", "虚幻");
81: skinName.Add("SystemDev Black", "夜色");
82: skinName.Add("SystemDev Blue", "蓝色");
83: //Office风格 添加OfficeSkins这个dll才可用 要先进行注册才能使用
84: skinName.Add("Office 2007 Blue", "Office 2007 蓝色");
85: skinName.Add("Office 2007 Black", "Office 2007 黑色");
86: skinName.Add("Office 2007 Silver", "Office 2007 银色");
87: skinName.Add("Office 2007 Green", "Office 2007 绿色");
88: skinName.Add("Office 2007 Pink", "Office 2007 粉色");
89: //额外风格 添加BonusSkin这个dll才可用 要先进行注册才能使用
90: skinName.Add("Bonus Coffee", "咖啡色调");
91: skinName.Add("Bonus Liquid Sky", "碧海蓝天");
92: skinName.Add("Bonus London Liquid Sky", "伦敦夜空");
93: skinName.Add("Bonus Glass Oceans", "玻璃海洋");
94: skinName.Add("Bonus Stardust", "星尘");
95: skinName.Add("Bonus Xmas 2008 Blue", "蓝色圣诞2008");
96: skinName.Add("Bonus Valentine", "粉色情人节");
97: skinName.Add("Bonus McSkin", "玻璃黑");
98: skinName.Add("Bonus Springtime", "春暖花开");
99: skinName.Add("Bonus Seven", "淡蓝色调");
100: skinName.Add("Bonus Darkroom", "黑色空间");
101: skinName.Add("Bonus Foggy", "朦胧记忆");
102: skinName.Add("Bonus Sharp Plus", "深黑色调");
103: skinName.Add("Bonus Sharp", "浓色灰黑");
104: skinName.Add("Bonus Seven Classic", "淡灰经典");
105: skinName.Add("Bonus High Contrast", "纯黑夜色");
106: skinName.Add("Bonus Dark Side", "浓黑一方");
107: skinName.Add("Bonus Pumpkin", "万圣节南瓜");
108: skinName.Add("Bonus Summer 2008", "阳光海滩");
109:
110: //自定义皮肤,通过SkinEdit制作
111: skinName.Add("BonusMySkin_Lilian_Test", "MySkin");
112: //皮肤与官方实例相比缺少5种,
113: //分别为Flat,Office 2003,Style3D,UltraFlat,Window Theme
114: SimpleButton imageButton = new SimpleButton();
115: foreach (SkinContainer cnt in SkinManager.Default.Skins)
116: {
117: string nameTemp = null;
118: foreach (DictionaryEntry item in skinName)
119: {
120: string halfName = string.Empty;
121: if (item.Key.ToString().Contains("SystemDev"))
122: {
123: halfName = item.Key.ToString().Replace("SystemDev", "");
124: }
125: else if (item.Key.ToString().Contains("Bonus"))
126: {
127: halfName = item.Key.ToString().Replace("Bonus", "");
128: }
129: else if (item.Key.ToString().Contains("Office"))
130: {
131: halfName = item.Key.ToString();
132: }
133: else
134: {
135: halfName = null;
136: }
137: if (halfName.Trim() == cnt.SkinName.Trim())
138: {
139: nameTemp = item.Key.ToString();
140: break;
141: }
142: }
143: if (string.IsNullOrEmpty(nameTemp))
144: {
145: continue;
146: }
147: imageButton.LookAndFeel.SetSkinStyle(cnt.SkinName);
148: GalleryItem gItem = new GalleryItem();
149: int groupIndex = -1;
150: if (nameTemp.IndexOf("SystemDev") > -1)
151: groupIndex = 0;
152: if (nameTemp.IndexOf("Office") > -1)
153: groupIndex = 1;
154: if (nameTemp.IndexOf("Bonus") > -1)
155: groupIndex = 2;
156: rgbiSkins.Gallery.Groups[groupIndex].Items.Add(gItem);
157: gItem.Image = GetSkinImage(imageButton, 32, 17, 2);
158: gItem.HoverImage = GetSkinImage(imageButton, 70, 36, 5);
159: gItem.Tag = cnt.SkinName;
160: gItem.Caption = skinName[nameTemp].ToString();
161: gItem.Hint = skinName[nameTemp].ToString();
162: rgbiSkins.Gallery.Groups[1].Visible = false;
163: }
164: }
165: private Bitmap GetSkinImage(SimpleButton button, int width, int height, int indent)
166: {
167: Bitmap image = new Bitmap(width, height);
168: using (Graphics g = Graphics.FromImage(image))
169: {
170: StyleObjectInfoArgs info = new StyleObjectInfoArgs(new GraphicsCache(g));
171: info.Bounds = new Rectangle(0, 0, width, height);
172: button.LookAndFeel.Painter.GroupPanel.DrawObject(info);
173: button.LookAndFeel.Painter.Border.DrawObject(info);
174: info.Bounds = new Rectangle(indent, indent, width - indent * 2, height - indent * 2);
175: button.LookAndFeel.Painter.Button.DrawObject(info);
176: }
177: return image;
178: }
179:
180: #endregion
181:
182: private void btn_Test_ItemClick(object sender, ItemClickEventArgs e)
183: {
184: DevFrmTest frmTest = new DevFrmTest();
185: frmTest.ShowDialog();
186: }
187: }
188: }
其中大部分均为DEV控件提供的皮肤,skinName.Add("BonusMySkin_Lilian_Test", "MySkin")这一个皮肤是我自己通过SkinEditor制作的皮肤,通过这个工具进行皮肤制作比较繁琐,希望大家有什么更好的方式可以告诉我。
下面重点说一下自定义皮肤的制作:
SkinEditor工具在DEV的默认安装目录下面,可以在开始菜单中看到。
打开SkinEditor工具,进入主界面。依次进入File->New创建新的Project,在对话框汇总输入Project的名称和皮肤名称,设置存储路径以及选择模板皮肤(新皮肤基于选择的模板皮肤进行制作),点击OK按钮,进入新创建的皮肤的制作。
注意:SkinEditor的详细使用方法可以查看SkinEditor的英文帮助文档或者官方使用说明,下面只是进行简单的介绍。
制作的详细方法大家进行慢慢摸索,我也只是刚刚接触。编辑完成保存新制作的皮肤即可。
我可以使用同样的方法为同一个Project添加多个自定义皮肤。可以通过ProjectManager工具管理Project中的皮肤,可以对其进行添加删除等。
完成之后,我们通过选工具可以把该Project文件编译成DLL。
编译成功后弹出下面提示框。
我们将生成的DLL拷贝到我们的程序中,然后添加引用(例如前面引用截图中的SkinProject_Test引用就是自己制作的皮肤Project生成的),其使用方法之后基本相同,详细参考前面程序。
下面查看一下皮肤效果:
默认风格
系统提供风格之一(这里没法每一个风格都进行截图,截取一个典型的)
自己制作的风格(只是修改少量,如按钮进行测试)
posted on 2013-05-23 15:25 jingkunliu 阅读(16677) 评论(0) 编辑 收藏 举报