Devexpress skin replacement

Source: Internet
Author: User

In devexpress, skin replacement is very simple. We don't need to create our own skin, so the official documents have a lot of skin packages. The following describes the problem.
Note: devexpress is used here.
8.1.5, which may not be supported in the old version. For the 7.x version, seeSource code.
Step 1: All forms are inherited from devexpress. xtraeditors. xtraform.
Step 2: Add two references:
Devexpress. bonusskins. v8.1
Devexpress. officeskins. v8.1
Step 3: The first line of the main function of the program class at the software entry Code Add:
Devexpress. userskins. bonusskins. Register ();

Devexpress. userskins. officeskins. Register ();

Devexpress. Skins. skinmanager. enableformskins ();

Application. enablevisualstyles ();

Application. setcompatibletextrenderingdefault (false );

Application. Run (New formmain ());
Step 4: Each window contains a defalooklookandfeel control,
Step 5: The software usually has a place to set skin. This place usually needs to enumerate all skin and put all skin in a comboboxedit. The Code is as follows:

Foreach (devexpress. Skins. skincontainer skin in
Devexpress. Skins. skinmanager. Default. skins)

Cmbappstyle. properties. Items. Add (skin. skinname );
Step 6: Set skin and how to set skin. You only need to set defalooklookandfeel for each window. The Code is as follows:
This. defaultlookandfeel1.lookandfeel. skinname
= Cmbappstyle. editvalue. tostring ();

or: String skinname = E. item. caption; // the MDI form is not tested.
devexpress. lookandfeel. userlookandfeel. default. setskinstyle (skinname);
currently, most of the problems are solved. The last problem is how to set skin, change the skins of all opened windows to the corresponding style? (In devexpress8.1.5, this function comes with itself, but it is not completely flawed.) The most basic method is the observer mode. However, I thought that in winforms, there should be methods to enumerate all opened windows. Sure enough, I found: application. openforms: to manage the skin of all windows in a unified manner, I wrote a base class, baseform, which inherits from
devexpress. xtraeditors. xtraform. Put defalooklookandfeel in baseform. And create a public attribute defalooklookandfeel. Then, write
(Form F in application. openforms)
If (F is
timerapp. forms. baseform)
(F as
timerapp. forms. baseform ). defaultlookandfeel. lookandfeel. skinname =
however, there is a problem with this method. An error occurs, saying "The openforms set has changed and cannot be enumerated! ", Depressed. We had to use the observer mode. The classes to be observed are as follows:
using system. collections. generic;
using system. text;
timerapp. forms;

Namespace timerapp. utils
Public class
Private Static skinsubject subject =
Private list <baseform> forms = new
List <baseform> ();

Public static skinsubject
Getinstance ()
If (subject = NULL) Subject = new
Skinsubject ();
Return subject;

Private skinsubject (){}

/// <Summary>

/// Register the observer
/// </Summary>
/// <Param
Name = "F"> </param>
Public void register (baseform
Forms. Add (f );

/// Deregister the observer
/// </Summary>

/// <Param name = "F"> </param>
Public void
Unregister (baseform F)
Forms. Remove (f );


/// <Summary>
/// Modify the skin of each observer
/// <Param
Name = "skinname"> </param>
Public void Policy (string
Foreach (baseform F in
F. defaultlookandfeel. lookandfeel. skinname =

This is not a standard observer mode. It also integrates the singon mode, because only one observer has, and the method in the observer does not need to be called back.

Note: Obtain the default skin name in devexpress: devexpress. Skins. skinmanager. defaultskinname

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.