Convert your WinForm Application

Source: Internet
Author: User
Exploitation. net technology can quickly develop applications, but if Microsoft's technology is applied, most programmers will feel the same way: the button or the button (only the text is different), the text box or the text box, the drop-down list or the drop-down list ........ the interface is no different from that in the system. No matter what the program is, at least this interface is not new.

It is true that there are also many third-party controls, such as Xceed Ultimate Suite and ComponentOne. studio, Infragistics. netAdvantage, etc. Most of these controls require a certain amount of time to master the usage of these controls, and some of them are not doing well. I have seen many of them drawn from a commercial control, it cannot be flexibly controlled on the IDE like the controls that come with VS.net. Now I want to show you a very simple skin-changing control. Let's take a look at the effect: have you seen the above interface? I am using standard controls of VS2005, and the function of skin changing is just a few lines of code. That is to say, the familiar controls are still used as usual. This set of controls has only one dll (IrisSkin2.dll) file and one skin folder. There are 22 subfolders in the skin folder, and each subfolders is actually a set of interface styles, that is to say, we can use 22 different styles. There are two ways to change the interface skin: (one by one) Beibei, Beibei the interface resources folder all the files to the location of the. exe file, and then in the program through skinEngine1.SkinFile = fileName (fileName is the skin file. ssk file location) to set the interface skin, this approach is usually we need to save a set of skin files in the Debug folder and the Release file each, also need to attach these files when releasing the program. (2) The embedded resource method is implemented in this article. The advantage of this method is that when a program is released (whether it is a Debug or Release version) when the program is released, vs automatically compiles the skin file into the exe file to reduce the number of files when the program is released, and you do not need to worry about the relative location of the program and the skin file. First, open the VS toolbox and add skin control components. For example, in the displayed "select toolbox items", click "Browse", find the IrisSkin2.dll file, and click "OK ", after closing the dialog window, the skin control component will appear in your toolbox (the group in which it appears depends on the group you added), for example:
(I accidentally added it to the print group, so don't scold me: P) Well, now I can write a program to test it. Make a simple form, as shown in the control on the interface, drag the skin component to the interface, and then add the skin resource file required by the program. Here I am adding resources. The procedure is as follows:
(1) Right-click "properties" on the WinForm project and click the "Resources" tab on the displayed page, add the required Skin resource file (use the "add existing file" command to add a skin file). For example, note that if the skin folder contains only *. the ssk file also contains other image files. We recommend that you add them as resources to the project. After adding, we can use Properties in the code. resources. the file name is used to obtain the content of these files. This method returns the binary data of the file content (byte []), and skinEngine1.SkinStream needs a Stream object, with msdn, we can construct a Stream object (new MemoryStream (byte [] bytes) with this binary data, and assign the value to the SkinStream attribute of the skin component. If you need to change the skin, re-construct the Stream object of a skin resource file, and then re-assign the value. The layout code of the interface control is very simple, so I will not paste it. I mainly put the background code here (in fact, it is also very simple, but note that because MemoryStream object is used, you need to add a reference to IO in the program reference assembly section: using System. IO;) the code is as follows: using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. IO;
Using System. Windows. Forms;

Namespace SkinForm
{
/// <Summary>
/// Note: This is a simple WinForm application that shows how to use skin change controls to implement the beautiful interface we need. The code is very simple.
/// By Zhou Gong
/// Time:
/// Starting address: http://blog.csdn.net/zhoufoxcn
/// </Summary>
Public partial class MainForm: Form
{
Private MemoryStream memoryStream;
Public MainForm ()
{
InitializeComponent ();
SetSkinFile (Properties. Resources. MacOS );
}

Private void btnOK_Click (object sender, EventArgs e)
{
If (rbMacOS. Checked)
{
SetSkinFile (Properties. Resources. MacOS );
}
Else if (rbMP10.Checked)
{
SetSkinFile (Properties. Resources. MP101 );
}
Else if (rbMSN. Checked)
{
SetSkinFile (Properties. Resources. MSN1 );
}
Else if (rbPage. Checked)
{
SetSkinFile (Properties. Resources. Page );
}
Else if (rbRealOne. Checked)
{
SetSkinFile (Properties. Resources. RealOne1 );
}
Else if (rbVista1.Checked)
{
SetSkinFile (Properties. Resources. vista1_green1 );
}
Else if (rbVista2.Checked)
{
SetSkinFile (Properties. Resources. Vista2_color11 );
}
Else
{
SetSkinFile (Properties. Resources. XPBlue1 );
}
}

Private void SetSkinFile (byte [] bytes)
{
MemoryStream = new MemoryStream (bytes );
// You can set the skin in two ways. One is to specify the position of the skin file,
// For example, skinEngine1.SkinFile = fileName (fileName is the position of the. ssk file)
// Specifies the file stream of the skin file, as shown in this program.
SkinEngine1.SkinStream = memoryStream;

}
}
}

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.