Devexpress learning-skin change

Source: Internet
Author: User
1. Create a ribbonform in the project and name it useskin. 2. Add a reference to devexpress. officeskins.
Devexpress. userskins. bonusskins

3. Set the text attribute of ribbonpage1 to skin.

The text attribute of ribbonpagegroup1 is set to: Skin replacement.

Create a new ribbongallerybaritem1 under ribbonpagegroup1 and set its caption attribute to: select your favorite skin and add the galleryitemclick event: ribbongallerybaritem1_galleryitemclick

4. Add:

Static void main () {// skin devexpress. userskins. officeskins. register (); devexpress. userskins. bonusskins. register (); devexpress. skins. skinmanager. enableformskins (); application. enablevisualstyles (); application. setcompatibletextrenderingdefault (false); application. run (new exercises. useskin ());}

 

 

5. Add the namespace using system. xml;

Add the code in the ribbongallerybaritem#click event:

Private void ribbongallerybaritem#click (Object sender, devexpress. xtrabars. ribbon. galleryitemclickeventargs e) {string name = string. empty; string caption = string. empty; If (ribbongallerybaritem1.gallery = NULL) return; caption = ribbongallerybaritem1.gallery. getcheckeditems () [0]. caption; // topic description caption = caption. replace ("topic:", ""); // name = bsipaintstyle. manager. pressedlink. item. tag. tostring (); // The topic name ribbongallerybaritem1.caption = "topic:" + Caption; xmldocument Doc = new xmldocument (); Doc. load ("skininfo. XML "); xmlnodelist nodelist = Doc. selectsinglenode ("setskin "). childnodes; foreach (xmlnode node in nodelist) {xmlelement Xe = (xmlelement) node; // converts the subnode type to xmlelement type if (Xe. name = "skinstring") {Xe. innertext = caption ;}} Doc. save ("skininfo. XML "); // xtramessagebox. show ("you have selected the topic:" + Caption );}

Add namespace

Using devexpress. xtrabars. helpers;
Using devexpress. lookandfeel;

6. Add the namespace using devexpress. xtraeditors;

Add code under load:

Public String defaultskinname; // skin private void useskin_load (Object sender, eventargs e) {skinhelper. initskingallery (ribbongallerybaritem1); checkfile (); // check the file getxmlskin (); // obtain the XML topic userlookandfeel. default. setskinstyle (defaultskinname); // set the topic style ribbongallerybaritem1.caption = "topic:" + defaskskinname;} # region check whether the XML file has public void checkfile () {try {If (system. io. file. exists ("skininfo. XML ") = false) {// xtramessagebox. show ("XML does not exist"); createxml () ;}} catch (exception ex) {xtramessagebox. show (ex. tostring (), "error", messageboxbuttons. OK, messageboxicon. error) ;}# region creates the XML file public void createxml () {xmldocument Doc = new xmldocument (); // creates the XML definition declaration xmldeclaration dec = Doc. createxmldeclaration ("1.0", "UTF-8", null); Doc. appendchild (DEC); // create the root node xmlelement root = Doc. createelement ("setskin"); xmlelement rootone = Doc. createelement ("skinstring"); // skin // insert one and two to the root node Doc. appendchild (Root); root. appendchild (rootone); Doc. save ("skininfo. XML ") ;}# endregion # region reads the content of the XML node public void getxmlskin () {try {xmldocument mydoc = new xmldocument (); mydoc. load ("skininfo. XML "); xmlnode ressnode = mydoc. selectsinglenode ("setskin"); defaultskinname = ressnode. selectsinglenode ("skinstring "). innertext;} catch (exception ex) {xtramessagebox. show (ex. tostring (), "error", messageboxbuttons. OK, messageboxicon. error); }}# endregion # endregion

Now you can select your favorite skin for your form.

Let's take a look at the results ....

 

 

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: info-contact@alibabacloud.com 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.