基於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生成的),其使用方法之后基本相同,詳細參考前面程序。
下面查看一下皮膚效果:
默認風格
系統提供風格之一(這里沒法每一個風格都進行截圖,截取一個典型的)
自己制作的風格(只是修改少量,如按鈕進行測試)