Load the XP style to Windows Forms in. net

Source: Internet
Author: User

To. NetInWindowsForm LoadingXPStyle

 

Introduction 

 

WhenWindows XPMany people are excited by the gorgeous interface they have when releasing their unique visual styles or themes. However, when. Net1.0When the official version was released, many people, includingWindowsThe form is not supported.Windows XPIs disappointing. My visual styleAPIFunctions and Microsoft's. NetThe framework development document was studied and then realized that. NetApplicationProgramAddXPStyle is not very difficult. 

 

The following describes how to add a simple program to your programs and controls.XPStyle. Content applies to some implementationsXPControls of style attributes.XPStyle, notification at the same timeWindowsThe system adds a topic to your applications and controls. 

 Conditions required for implementation 

You need some conditions to implement this function:

1.Microsoft. NET Framework SDK(Required)

 2.Microsoft Visual Studio. NETHe helps you designWindowsForm (optional)

3.Windows XPOperating System (optional): supports the official version of the topic. 

 

Enter the subject 

 

OpenVisual Studio. NETCreate a newWindowsApplication. Here I will useC #ComeProgramming LanguageSo if you useVisual Basic. net, You need to convertCode. After you have created a project, openAssemblyinfo. CSFile, inAssemblytitle,AssemblydescriptionAndAssemblyversionIn, modifyAssemblydelaysignIsTrue. You also need to modifyAssemblykeyfileIs@ ".. \ Keyfile. SNK",Keyfile. SNKThe file will be created or copied later. 

 

After you complete the preceding steps, your code looks like the following:

Using system. reflection;

Using system. runtime. compilerservices;

[Assembly: assemblytitle ("theme test")]

[Assembly: assemblydescription ("testing Windows XP visual styles.")]

[Assembly: assemblyconfiguration ("")]

[Assembly: assemblycompany ("")]

[Assembly: assemblyproduct ("")]

[Assembly: assemblycopyright ("")]

[Assembly: assemblytrademark ("")]

[Assembly: assemblyculture ("")]

[Assembly: assemblyversion (" 1.0.0.0 ")]

[Assembly: assemblydelaysign (true)]

[Assembly: assemblykeyfile (@ "... \ Keyfile. SNK")]

[Assembly: assemblykeyname ("")] 

 

OpenForm1.csAdd someWindowsForm control, suchListviews,Buttons,Groupboxes,ProgressbarsOr more, the following lists all supportedXPStyle hole:

Textbox,RichTextBox,Hscrollbar,Vscrollbar,Progressbar,Tabcontrol,Mainmenu,Contextmenu,ComboBox,DataGrid,ListBox,Listview,Treeview,Datetimepicker,Monthcalendar,Splitter,Trackbar,Statusbar,Toolbar,Treeview,Listview.

 

Some of these controls are supported by default, and some other specific controls areButtonbase,Groupbox, OrLabelInherited, you need to set theirFlatstyleThe property isSystemAnd I will give some brief descriptions. 

 

After you compile this application, you will find thatWindows FormsIt does not look likeXPStyle. To find the reason, see. 

 Windows XPDisplay principles of styles

Simple Description:Comctl32.dll, Version:6.Comctl32.dllOr the common controls have been used for a long time. This dynamic connection library is used by the basic controls.User32.dllProvided to the user control. In version6OfComctl32.dllAll the controls are put in, so they support topics. But the new versionComctl32.dllUnlike the previous versionWindows XPStyle, you must useComctl32.dllSuchWindows XP. 

 

For the supported controls, their styles are related to some special theme resources, which are used for drawing on the customer interface. For those derived fromButtonbase,GroupboxAndLablelTheFlatstyleSet propertyFlatstyle. SystemEnumeration values, so that the system can draw them. 

 

In order for the operating system to add a theme style to our controls, you need to notify the system to make the version6OfComctl32.dllAs the default value. The default version is used.5OfComctl32.dll,. NetThe same is true for the program, but we will allow the program to use the version during execution.6OfComctl32.dll. 

 

AddXMLFile, the file is named [your application name]. EXE. manifest, [Your application name] refers to the master generated by project CompilationEXEFile. Set the compilation type"None".

 

Assume that yourAssemblyinfo. CSAs mentioned above, the newly created [your application name]. EXE. manifestThe file should look like the following:

 

<? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?>

 

<Assembly

Xmlns = "urn: Schemas-Microsoft-com: ASM. V1"

Manifestversion = "1.0">

<Assemblyidentity

Version = "1.0.0.0"

Processorarchitecture = "x86"

Name = "theme test"

Type = "Win32"/>

<Description> testing Windows XP visual styles. </description>

<Dependency>

<Dependentassembly>

<Assemblyidentity

Type = "Win32"

Name = "Microsoft. Windows. Common-Controls"

Version = "6.0.0.0"

Processorarchitecture = "x86"

Publickeytoken = "6595b64144ccf1df"

Language = "*"/>

</Dependentassembly>

</Dependency>

</Assembly>

 

Replace the above"Version"And"Name"Attribute value so that it corresponds to the sameAssemblyversionAndAssemblytitleAttribute. That"Descryiption"The element must be the same as yourAssemblydescriptionThe property is correct.

Next, open the Command Prompt window to modify the output path of your project."Bin \ debug"As the root directory of the Project path. Suppose you have addedSn.exeIf the path of the tool is strongly named to your system environment variables, enter the following in the command line:

Sn.exe-k... \ Keyfile. SNK

The preceding step generatesKeyfile. SNKPublic key file, in order to make your program integrated into a strong type assembly, this public key is required. This is required in many cases.

 

AddMnifestInformation 

 

The directory in which you want to output the project file. In my example, it is a simpleWindowsapplication1.exeFile. 

 

Now, returnVisul Studio. NET, Click the File menu->Open and browse your application, suchWindowsapplication1.exeAnd click open. We will see a resource file management tree. 

 

1. Right-click the root node and select "Add Resource ".

2. Click "import" and find it in your project path.Windowsapplication.exe. mnifestAnd open it.

3In the Custom Resource Type dialog box, enterRt_manifestClick OK.

4. Save all files and let us go back to the previous resources to browse the tree. Now we can seeRt_manifest.

5. Click to select the newly added resource file under it. The common name is101. Modify itsIDThe value is1And save your application again.

6Close the resource browsing window and return to the command line prompt and enter the following command:

Sn-r windowsapplication1.exe... \ Keyfile. SNK

After the command is executed, some version information is output, and the following information is displayed:

Assembly 'windowsapplication1.exe 'successfully re-signed

Run your. NetApplication, you will seeWindows XPStyle.

 

Summary 

 

You do not need to do a lot of workWindows XPAdd visual styles to your applications and controls. Using these new styles will bring new visual effects to your forms, which are often used in commercial applications. Many companies are devoted to developing such things, but now you can do it without doing a lot of work. 

 

RememberFlatstyleProperty ControlFlatstyle. SystemAnd addManifestThe resource is like the Template File above. After all these are done, the rest is to sign the assembly. If you want to test your application or you have the permission to sign it, you can use the following command to disable the Assembly Verification: 

 

Sn.exe-VR windowsapplication1.exe 

 

Act now and addXPStyle makes your product more distinctive. This will not take much time, but the effect is obvious. 

 

About Heath Stewart

Heath Stewart is a happily married software engineer originally from Nebraska and a graduate of Iowa State University in

Ames, Iowa. with nothing much to do in either State, heath started programming early in life when gopher ruled and the Internet wasn't got cialized, and enjoys continuous research and development in new versions and frameworks. fluent in your different programming languages, he has developed into large software solutions for companies in different areas, such as Internet filtering, intrusion detection systems, production management systems, Web sites for various purposes, and data analysis tools. he also enjoys photography.

 

Currently, Heath is the Director of Technology at proplanner, a web-based production planning system that primarily uses. net where he designed a multi-tiered environment and supports multiple front-ends (such as a legacy Java interface on PDM) and back-ends (such as Web Services, RDBMS's, file-based Io, and PDM ). 

 

Heath is now an editor for codeproject and is happy to help the development community as a Microsoft MVP (C #). 

1. application. enablevisualstyles method (applicable only to. NET 1.1 and later versions)

Before executing the application. Run (...) method in the main method, run the application. enablevisualstyles () method to automatically apply the XP style to the controls in the subsequent application. Note the following points:

All controls must be in the default state and cannot change attributes such as border style and background color. If the style attributes of the System Option (such as the flatstyle of the button), You must select system;

This method can run completely normally in wiin2003, but the icon on the toolbar in Win XP cannot be displayed. (this may be an XP bug. The following method can be used to solve this problem );

2. Add the manifest file (applicable to all Windows applications)

Adding yourapplicationname.exe. manifest to the execution file in the same directory can quickly meet our needs. The content of the file is as follows (the underline must be changed as needed ):

<? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?>

<Assembly xmlns = "urn: Schemas-Microsoft-com: ASM. V1" manifestversion = "1.0">

<Assemblyidentity

Version ="1.0.0.0"

Processorarchitecture = "x86"

Name ="CompanyName. productname. yourapp"

Type = "Win32"

/>

<Description>Your application description here. </Description>

<Dependency>

<Dependentassembly>

<Assemblyidentity

Type = "Win32"

Name = "Microsoft. Windows. Common-Controls"

Version = "6.0.0.0"

Processorarchitecture = "x86"

Publickeytoken = "6595b64144ccf1df"

Language = "*"

/>

</Dependentassembly>

</Dependency>

</Assembly>

Turn: http://blog.csdn.net/zhzuo/archive/2004/04/22/22030.aspx

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.