Winform skin replacement (irisskin2.dll)

Source: Internet
Author: User

This article mainly explains how to use irisskin2.dll to dynamically change the skin of the winform interface. before the operation, make sure that there are irisskin2.dll and some slightly more beautiful skin files (. (End of SSK), place them in what you think is appropriate. In order to demonstrate how to place irisskin2.dll and skin files under debug of the application, all skin files are placed in the skin-named folder, as shown in

The skin file in the skin folder and the ini configuration file defined by myself (this file will be described later. Information about the ini configuration file has been mentioned in my above article, here, I will not go into details about how to operate the INI file. The link address is

Http://www.cnblogs.com/wangsaiming/archive/2011/04/25/2028601.html

)

Now, let's take a look at what functions I want to implement and what kind of skin I want to apply, so that we can give a detailed explanation later. As follows:

Show Yes

In the top two, there is a sub-menu item of the system skin. The content of the sub-menu item is not entered, but is dynamically bound in the background, that is to say, when the program is running, how many skin files are there?

The number of skins is added to the system skin menu. When you select each skin, the interface changes with the selected skin.

The following describes how to implement it:

First, you must reference the irisskin2.dll file. in the toolbox, choose> General> select items. A window is displayed as follows:

Click the Browse button and select the irisskin2.dll you want to add. This control is found in the toolbox and added to the form interface.

Now you can perform the operations. when loading the form, bind the custom binding skin method.

The Code is as follows:

Private void form1_load (Object sender, eventargs e) {bindskinengine (); // call the method of binding skin}

The following is a custom method for skin binding:

View code

Private void bindskinengine ()
{

// Obtain the default skin path
Inifiles ini = new inifiles (sskinpath + @ "\ skin. ini ");
String currentskin = ini. inireadvalue ("current", "current ");
If (currentskin. indexof ('.')! =-1)
{
Sskinname = currentskin. Split ('.') [0];

}
Skinengine1.skinfile = sskinpath + "\" + currentskin;
// Obtain all skin Information
If (! Directory. exists (sskinpath ))
{

MessageBox. Show ("failed to load system skin! "," Prompt ", messageboxbuttons. OK, messageboxicon. Error );
Return;
}
Directoryinfo mydir = new directoryinfo (sskinpath );
Foreach (filesysteminfo FSI in mydir. getfilesysteminfos ())
{

If (FSI is fileinfo)
{

// Read the skin file in the skin folder
Fileinfo Fi = (fileinfo) FSI;
String x = path. getdirectoryname (Fi. fullname );
String S = path. getextension (Fi. fullname );
String y = path. getfilenamewithoutextension (Fi. fullname );
String F = path. getfilename (Fi. fullname );
If (S = ". SSK ")
{

// Create a toolbar
Toolstripmenuitem skintoolstripmenuitem = new toolstripmenuitem ();
Skintoolstripmenuitem. Name = Y + "toolstripmenuitem ";
Skintoolstripmenuitem. size = new size (152, 22 );
Skintoolstripmenuitem. Text = y;
Skintoolstripmenuitem. Click + = new eventhandler (skintoolstripmenuitem_click );
Skintoolstripmenuitem. checkonclick = true;
// Current skin selection status
If (F = currentskin)
{
Skintoolstripmenuitem. checkstate = checkstate. checked;

}
Else
{
Skintoolstripmenuitem. checkstate = checkstate. unchecked;

}
This. System skin toolstripmenuitem. dropdownitems. Add (skintoolstripmenuitem );

}
}
}
}

There is an inifiles, which is a class for customizing the INI file (

)

Sskinpath and sskinname are declared Variables

As shown below

# Region "declaring variables"
Private string sskinname = "";
Private string sskinpath = application. startuppath + @ "\ skin"; // obtain the skin path
# Endregion

Skintoolstripmenuitem. Click + = new eventhandler (skintoolstripmenuitem_click );

Skintoolstripmenuitem_click is also customized as follows:

View code

Private void skintoolstripmenuitem_click (Object sender, eventargs E)
{
// Change the selection status
Foreach (toolstripmenuitem item in system skin toolstripmenuitem. dropdownitems)
{

If (item. Text = sender. tostring ())
{

Item. checkstate = checkstate. checked;
Sskinname = sender. tostring ();

}
Else
{

Item. checkstate = checkstate. unchecked;

}

}
// Skin change
Skinengine1.skinfile = sskinpath + "\" + sender. tostring () + ". SSK ";

// Boot skin write Configuration
Inifiles ini = new inifiles (sskinpath + @ "\ skin. ini ");
INI. iniwritevalue ("current", "current", Sender. tostring () + ". SSK ");
This. updatestyles ();


}

This is over. An ini configuration file is as follows:

The default configuration file for this form operation.

It's a bit messy. If you don't understand it, you can come to Q: 1983512803.

Related Article

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.