Based on the use of Step DevExpress (VS), further use of devexpress to change the WinForm skin, suitable for beginners.
Tips:
1. For Repositoryitemcombobox without EditValue property in the DevExpress menu, the selected value cannot be obtained directly, but can be obtained by converting it to a Comboboxedit control in its event. As follows:
private void Repositoryitemcombobox1_selectedvaluechanged (object sender, EventArgs e) { Comboboxedit Ricombobox = sender as Comboboxedit;
2, in the design interface code such as: BaseFormDesigner.cs, manually add the event to the specified control (repositoryitemcombobox), the code is as follows:
This.repositoryItemComboBox1.SelectedValueChanged + = new System.EventHandler (this.repositoryitemcombobox1_ selectedvaluechanged);
To implement its specific functions in the corresponding BaseForm.cs, the code is as follows:
<summary>////The event triggered when the value of a ComboBox menu item is changed manually///</summary>// <param name= "Sender" > </param>// <param name= "E" ></param> private void repositoryitemcombobox1_ SelectedValueChanged (object sender, EventArgs e) { Comboboxedit Repositoryitemcombobox = sender As Comboboxedit; This.defaultLookAndFeel1.LookAndFeel.SkinName = RepositoryItemComboBox.EditValue.ToString (); }
Inter-code relationships: The program class primarily registers the skin to be used and runs that interface; The Commonfunctions class implements common functions primarily BaseForm class inherits from DevExpress.XtraEditors.XtraForm, mainly realizes some basic common operation, Skinsubject class accumulates common operation or commonality of those classes common BaseForm class (singleton, simple observer to implement) The Appforma, APPFORMB classes inherit from the BaseForm class and share the BaseForm class attributes.
The specific instance code (excluding the interface design code) is as follows:
Program.cs
Using system;using system.collections.generic;using system.linq;using system.threading.tasks;using System.windows.forms;namespace testexpressskins{ Static class program {// <summary> /// The main entry point for the application. // </summary> [STAThread] static void Main () { DevExpress.UserSkins.BonusSkins.Register (); DevExpress.UserSkins.OfficeSkins.Register (); DevExpress.Skins.SkinManager.EnableFormSkins (); Application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Application.Run (New BaseForm ()); Application.Run (New Appforma ()); Application.Run (Appforma.singlon ());}}}
CommonFunctions.cs
Using devexpress.xtrabars;using devexpress.xtraeditors;using devexpress.xtraeditors.repository;using System;using System.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace Testexpressskins{class Commonfunctions {#region field #endregion #region Singleton Priva Te static commonfunctions commfuncinstance = null; Private Commonfunctions () {} public static commonfunctions Singlon () {if (null = = commfuncinstance) {commfuncinstance = new commonfunctions (); } return commfuncinstance; } #endregion #region Common methods//<summary>////skin all enumerated and placed in a comboboxedit///</SU mmary>//<param name= "Comboboxedit" ></param> public void Addappstyles2comboboxedit (ComboBox Edit comboboxedit) {foreach (DevExpress.Skins.SkinContainer skin in DevexpRess. Skins.SkinManager.Default.Skins) {ComboBoxEdit.Properties.Items.Add (skin. Skinname); }}///<summary>///skin all enumerated and placed in a comboboxedit///</summary>//<para M name= "Repositoryitemcombobox" ></param> public void Addappstyles2repositoryitemcombobox (Repositoryitemco Mbobox repositoryitemcombobox) {foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinMa Nager. Default.skins) {RepositoryItemComboBox.Items.Add (skin. Skinname); }} public void Addappstyles2baredititem (Baredititem baredititem) {string edititemtype = Baredititem.gettype (). ToString (); Switch (edititemtype) {case "Repositoryitemcombobox": Addappstyles2repositor Yitemcombobox (Baredititem.edit as Repositoryitemcombobox); Break Case "Repositoryitem** ": Break; Case "repositoryitem***": break; }} #endregion #region Private method public bool Tmpfunc () {bool bflag = true; return bflag; } #endregion}}
SkinSubject.cs
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace testexpressskins{public class Skinsubject {#region field private list<baseform> forms = New List<baseform> (); The same Style dialog box collection #endregion #region a singleton private static skinsubject subject = NULL; public static Skinsubject getinstance () {if (subject = = null) Subject = new Skinsubject (); return subject; } private Skinsubject () {} #endregion #region Common method//<summary>///Registered Observer </summary>//<param name= "F" ></param> public void Register (BaseForm f) { Forms. ADD (f); }///<summary>//cancellation of Observers///</summary>//<param name= "F" ></param> public void UnRegister (BaseForm f) {forms. Remove (f); }///<summary>//Modify the skin of each observer///</summary>//<param name= "Skinname" >&L t;/param> public void Notify (string skinname) {foreach (BaseForm f in forms) { F.lookandfeelcontrol.lookandfeel.skinname = Skinname; }} #endregion #region private Method #endregion}}
BaseForm.cs
Using devexpress.lookandfeel;using devexpress.xtrabars;using devexpress.xtraeditors;using Devexpress.xtraeditors.repository;using system;using system.collections.generic;using System.ComponentModel;using System.data;using system.drawing;using system.linq;using system.text;using system.threading.tasks;using System.windows.forms;namespace testexpressskins{public partial class BaseForm:DevExpress.XtraEditors.XtraForm Form {#region field private commonfunctions commfunc = null; #endregion #region Property Public Defaultlookandfeel Lookandfeelcontrol {set { } get {return this.defaultlookandfeel1; }} public int Tempa {set {} get { return 1; }} #endregion #region constructor public BaseForm () {InitializeComponent(); Commfunc = Commonfunctions.singlon (); #endregion #region dialog box or spatial-related method private void Form1_Load (object sender, EventArgs e) { Commfunc.addappstyles2comboboxedit (Cmbappstyle); Commfunc.addappstyles2repositoryitemcombobox (This.repositoryitemcombobox1); private void Cmbappstyle_selectedindexchanged (object sender, EventArgs e) {This.defaultlookand Feel1.LookAndFeel.SkinName = CmbAppStyle.EditValue.ToString (); }///<summary>///The event triggered when the ComboBox menu item value is changed manually///</summary>//<param name= "Sender" ></param>//<param name= "E" ></param> private void Repositoryitemcombobox1_sel Ectedvaluechanged (object sender, EventArgs e) {Comboboxedit Repositoryitemcombobox = sender as ComboBox Edit; This.defaultLookAndFeel1.LookAndFeel.SkinName = RepositoryItemComboBox.EditValue.ToString (); } #endregion #region Private Method #endregion}}
AppFormA.cs
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;namespace testexpressskins{public partial class Appforma:baseform//form {#region field BaseForm app FORMB = null; #endregion #region Property public int Tempa {set {} get {return 1; }} #endregion #region a singleton private static appforma appformainstance = null; #region Constructor Private Appforma () {InitializeComponent (); Skinsubject.getinstance (). Register (this); } #endregion public static Appforma Singlon () {if (null = = Appformainstance) { Appformainstance = new Appforma (); } return appformainstance; #endregion #region dialog box or spatial-related method private void Bgo2b_click (object sender, EventArgs e) { if (null = = APPFORMB)//{//APPFORMB = new APPFORMB (); } APPFORMB = Appformb.singlon (); This. Hide (); Appformb.show (); } #endregion #region Private Method #endregion}}
AppFormB.cs
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;namespace testexpressskins{public partial class Appformb:baseform//form {#region field BaseForm app FormA = null; #endregion #region Property public int Tempa {set {} get {return 1; }} #endregion #region a singleton private static APPFORMB appformbinstance = null; #region Constructor Private Appformb () {InitializeComponent (); Skinsubject.getinstance (). Register (this); } #endregion public static APPFORMB Singlon () {if (null = = Appformbinstance) { Appformbinstance = new APPFORMB (); } return Appformbinstance; #endregion #region dialog box or spatial-related method private void Bgo2a_click (object sender, EventArgs e) { if (null = = Appforma)//{//Appforma = new Appforma (); } Appforma = Appforma.singlon (); This. Hide (); Appforma.show (); } #endregion #region Private Method #endregion}}
Use devexpress to change WinForm skin (VS)