Lecture 3: Asp.Net+Autofac+EF/ADO.NET Winform OA(3) - Enable DevExpress Skin Function

Keywords: C# Database xml

Author: Ditch Oil

Entering the front page

Preface:

Because the color of the system is too monotonous, we decided to enable DevExpress skin-changing function to make the interface more beautiful! ___________

The author's Dev Express has been changed to 17.2.3, but if you don't want to upgrade, you can continue to use the old version of Dev Express, because the old and the new are not so different!

1. First, we go into Program and add the following code in Main():

1 //Enable skin
2             DevExpress.Skins.SkinManager.EnableFormSkins();
3             DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged();
4             DevExpress.Skins.SkinManager.EnableMdiFormSkins();

2. Open the frmMain form and add an Xtra Tabbed Mdi Manager, Bar Manager, Dock Manager, DefaultLook AndFeel, named as:

  

 

3. A new BarEditItem named beItemColor is added at the bottom of Bar.

  

4. Create a new Skins table in the database to save the skin selected by the user. (Of course, you can write to Xml, and you can skip this section if you choose to write to 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'user 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'user designation codes' , @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'Skin code' , @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'Skin name' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Skins', @level2type=N'COLUMN',@level2name=N'Name'
38 GO
Skins

5. Update the entity in the ivw.Models class to save the changed skin to the database later.

  

6. Enter the frmMain background and write the following code:

 1         #region Enable skin 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         #endregion
SetSkins

7. Use this method in constructors.

1         public frmMain()
2         {
3             InitializeComponent();
4             SetSkins();
5         }

8. Let's try how it works.

 

9. Good-looking skin appears in front of your eyes, more skin please try it yourself. A kind of

Posted by hucklebezzer on Wed, 13 Feb 2019 22:18:19 -0800