作者:地溝油 進入首頁 前言: 由於系統顏色太單調,所以決定啟用DevExpress換膚功能,讓界面更美觀! 作者的DevExpress已更換到17.2.3了,不過要是不想升級的話,也可以繼續沿用舊版的DevExpress喲,因為舊的和新的區別不大喲! 1.首先我們進入Program,在Main() ...
作者:地溝油
前言:
由於系統顏色太單調,所以決定啟用DevExpress換膚功能,讓界面更美觀!
作者的DevExpress已更換到17.2.3了,不過要是不想升級的話,也可以繼續沿用舊版的DevExpress喲,因為舊的和新的區別不大喲!
1.首先我們進入Program,在Main()方法出加入以下代碼:
1 //啟用皮膚 2 DevExpress.Skins.SkinManager.EnableFormSkins(); 3 DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged(); 4 DevExpress.Skins.SkinManager.EnableMdiFormSkins();View Code
2.打開frmMain窗體,加入一個XtraTabbedMdiManager,BarManager,DockManager,DefaultLookAndFeel,分別命名為:
3.在底部Bar出新增一個BarEditItem,命名為beItemColor。
4.在資料庫新建一個Skins表,用來保存用戶選擇過的皮膚。(當然,可以寫入Xml,選擇寫入Xml者可略過本節)
1 USE [IVW] 2 GO 3 4 /****** Object: Table [dbo].[Skins] Script Date: 2017/11/25 19:53:47 ******/ 5 SET ANSI_NULLS ON 6 GO 7 8 SET QUOTED_IDENTIFIER ON 9 GO 10 11 CREATE TABLE [dbo].[Skins]( 12 [Id] [int] IDENTITY(1,1) NOT NULL, 13 [UserId] [int] NOT NULL, 14 [UserCode] [nvarchar](10) NOT NULL, 15 [Values] [nvarchar](50) NOT NULL, 16 [Name] [nvarchar](50) NOT NULL, 17 [DateTime] [datetime] NOT NULL, 18 CONSTRAINT [PK_Skins] PRIMARY KEY CLUSTERED 19 ( 20 [Id] ASC 21 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 22 ) ON [PRIMARY] 23 GO 24 25 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Skins', @level2type=N'COLUMN',@level2name=N'Id' 26 GO 27 28 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'用戶Id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Skins', @level2type=N'COLUMN',@level2name=N'UserId' 29 GO 30 31 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'用戶代碼' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Skins', @level2type=N'COLUMN',@level2name=N'UserCode' 32 GO 33 34 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'皮膚代碼' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Skins', @level2type=N'COLUMN',@level2name=N'Values' 35 GO 36 37 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'皮膚名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Skins', @level2type=N'COLUMN',@level2name=N'Name' 38 GOSkins
5.在ivw.Models類更新該實體,方便以後把更改過的皮膚保存到資料庫中。
6.進入frmMain後臺,寫入以下代碼:
1 #region 啟用皮膚 void SetSkins() 2 void SetSkins() 3 { 4 foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins) 5 { 6 ricbColor.Items.Add(skin.SkinName); 7 } 8 9 dLookAndFeel.LookAndFeel.SkinName = beItemColor.EditValue.ToString(); 10 11 this.beItemColor.EditValueChanged += BeItemColor_EditValueChanged; 12 } 13 14 private void BeItemColor_EditValueChanged(object sender, EventArgs e) 15 { 16 dLookAndFeel.LookAndFeel.SkinName = beItemColor.EditValue.ToString(); 17 } 18 #endregionSetSkins
7.在構造函數中使用這個方法。
1 public frmMain() 2 { 3 InitializeComponent(); 4 SetSkins(); 5 }View Code
8.讓我們試試效果如何。
9.好看的皮膚就呈現在眼前咯,更多皮膚請自己嘗試喲。