Winform Skin-how to use IrisKin2

Source: Internet
Author: User

This article mainly explains how to use IrisSkin2.dll to dynamically change the skin of the WinForm interface, before operation, should ensure that there are IrisSkin2.dll and some of the slightly prettier skin files (end of. SSK), put them in a position that you think is appropriate, in order to demonstrate using my IRI SSkin2.dll and skin files are placed under the application's debug, and all skin files are placed under a skin-named folder as shown

Skin files under the Skins folder and my own defined INI profile (this file will be described later, the information about the INI configuration file has been mentioned in the above article, no longer explain in detail about the Operation INI file link address is

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

Now first of all I want to achieve what kind of function and application of the skin after the first down, in order to explain in detail later. As follows:

As a

In the top two, there is a system Skin submenu items, sub-menu item content is not entered, but in the background of dynamic binding, that is, how many of your skin files, when the program is running

How many skins will be added to the menu item in the system skin, and when you select each skin, the interface will change as you select the skin.

Here's how to do it:

To refer to the IrisSkin2.dll file first, select the-->> selection under the-->> General bar of the Toolbox and a popup window will appear as follows:

After you click the Browse button to select the IrisSkin2.dll you want to add, you will find the control in the Toolbox and add the control to the form interface.

It is now possible to manipulate the custom binding skin method when the form is loaded

The code is as follows:

+ View Code?
private void Form1_Load(object sender, EventArgs e)       {           BindSkinEngine();//调用绑定皮肤的方法       }

Here is a custom way to bind the skin:

View CodePrivatevoidBindskinengine ()
{

//Get the default skin path
inifiles INI=NewInifiles (Sskinpath+@"\skin.ini");
stringCurrentskin=INI. Inireadvalue (" Current", " Current");
if(Currentskin.indexof ('.') !=-1)
{
Sskinname=Currentskin.split ('.')[0];

}
Skinengine1.skinfile=Sskinpath+"\\"+Currentskin;
//Get all skin information
if (!directory.exists (Sskinpath))
{

MessageBox.Show ("system skin failed to load! ", "Tips", MessageBoxButtons.OK, Messageboxicon.error);
return;
}
DirectoryInfo Mydir=NewDirectoryInfo (Sskinpath);
foreach(FileSystemInfo FSIinchMydir. Getfilesysteminfos ())
{

if(FSI isFileInfo)
{

//skin files for reading skin folders
FileInfo fi=(FileInfo) FSI;
stringx=Path.getdirectoryname (FI. FullName);
strings=path.getextension (FI. FullName);
stringy=path.getfilenamewithoutextension (FI. FullName);
stringF=Path.getfilename (FI. FullName);
if(S==". SSK")
{

//new Toolbar
ToolStripMenuItem Skintoolstripmenuitem=NewToolStripMenuItem ();
Skintoolstripmenuitem.name=y+"ToolStripMenuItem";
Skintoolstripmenuitem.size=NewSize ( the, A);
Skintoolstripmenuitem.text=y;
Skintoolstripmenuitem.click+=NewEventHandler (Skintoolstripmenuitem_click);
Skintoolstripmenuitem.checkonclick=true;
//Current skin Check status
if(f==Currentskin)
{
Skintoolstripmenuitem.checkstate=checkstate.checked;

}
Else
{
Skintoolstripmenuitem.checkstate=checkstate.unchecked;

}
This. System Skin TOOLSTRIPMENUITEM.DROPDOWNITEMS.ADD (Skintoolstripmenuitem);

}
}
}
}

There's a inifiles in it. This is the class of the custom action INI file (the Operation INI file has been previously spoken (

), which is not explained in detail here)

Sskinpath and Sskinname are declared variables.

As shown below

#region"Declaring variables"
PrivatestringSskinname="";
PrivatestringSskinpath=Application.startuppath+@"\skin";//get the path to the skin
#endregionThe main thing inside is Skintoolstripmenuitem.click + = new EventHandler (Skintoolstripmenuitem_click);

The Skintoolstripmenuitem_click is also customizable as follows:

View CodePrivatevoidSkintoolstripmenuitem_click (Objectsender, EventArgs e)
{
//Change Selection Status
foreach(ToolStripMenuItem IteminchSystem 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 up skin write configuration
inifiles INI=NewInifiles (Sskinpath+@"\skin.ini");
Ini. Iniwritevalue (" Current", " Current", sender. ToString ()+". SSK");
This. UpdateStyles ();


}

Here is the end of this, there is an INI configuration file as follows:

Tony.Chen.Cnblogs

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.