Use Windows XP style controls on forms

  
        \tOne. Summary Windows XP pioneered a new Windows user interface (UI) that gives users a modern, ultra-fashion feel. Windows XP has created a new style of controls with shiny controls with rounded corners and a futuristic progress bar. Now Visual Studio.Net also has such controls. So developers want to be able to use such cool controls in their own programs. The answer is yes, all the programmer has to do is add some references and a resource file. This article introduces an example to introduce how to apply the Windows XP style of the control to your own program under Visual Basic and Visual C#. Note: The control style features described in this article can only be implemented in Windows XP applications. Two. Introduction Let's start with a comparison of control styles. Controls under Windows XP have a completely new look. The illustrations are as follows: The controls provided in Visual Studio.Net are the same as those under Windows XP, but their appearance is quite different. The illustration is as follows: This article shows you how to make the controls in Visual Studio the same as the controls under Windows XP, with a cool look and a good user interface. You can think of a form as consisting of two separate parts: a client area and a non-client area. All programs running on the Windows XP operating system have a non-client area that includes: a form frame, a title bar, and a scroll bar for non-client areas. The operating system automatically applies Windows XP style to non-client areas, so even if you don't do anything, you can see that your program has a new style of form frame, title bar, and scroll bar when running on Windows XP. And what we really have to do is to make the controls in the client area also have the style of Windows XP. three. Implementation Principle The appearance of the non-client area is determined by the visual style currently applied. The visual style of an application or operating system can be changed. As mentioned above, when an application runs on Windows XP, the scroll bar and title bar of the form immediately change the look and feel. As long as the application uses the version of Comctl32.dll version 6.0, some of the controls automatically render the new look. These controls are as follows: Other controls require certain conditions. Specifically, controls (Button, RadioButton, GroupBox, and CheckBox) that inherit from the System.Windows.Forms.ButtonBase class have a FlatStyle property. This property indicates that the control should be drawn first. By setting this property, the control can be drawn in the following ways: You can see that when the FlatStyle property is set to System, the appearance of the control is determined by the user's operating system settings. In this case, if the user's operating system is Windows XP, the appearance of the corresponding control will be Windows XP style. When the FlatStyle property is set to System, the controls that change the visual style are as follows: Button Control RadioButton Control CheckBox Control GroupBox Control Finally, there are some controls that are the same under Windows XP and Visual Studio. These controls are as follows: Label Control LinkLabel Control DomainUpDown control NumericUpDown control CheckedListBox control IV. Using the Manifest File If you want to use the look and feel of Windows XP in your application, you must add a Manifest file to your project (a file used to determine the resource during the build process). This file indicates that the Comctl32.dll file with version 6.0 is applied in the project (as long as this file exists). The version of Comctl32.dll file with version 6.0 includes some new controls and some new features of the control. The biggest difference between it and the previous version is that it supports the change of the appearance of the control. Unlike previous versions, version 6.0 of Comctl32.dll is not re-released. You can only use its dynamic link library (DLL) in the operating system that contains it. Windows XP includes both version 5.0 and version 6.0 (by default, the application uses Comctl32.dll version 5.0). In the version 6.0 of Comctl32.dll, user controls and general controls are included. You only need to change the dll files associated with these controls to make them look like Winodws XP. In order to coordinate with the user's computer operating system, you must create a Manifest file in your application to explicitly specify that its form control uses version 6.0 of Comctl32.dll. The Manifest file is an XML file that is included in your program as a resource or as a separate file in the executable directory. Therefore, in order for your application to have the same look and feel as Windows XP, you must: If the control has the FlatStyle property, set it to FlatStyle.System. Create a Manifest file and bundle the version of Comctl32.dll with version 6.0 into your application (the Manifest file in the example below can bundle the Comctl32.dll into any application built with Visual Studio.Net). Add this resource (Manifest file) to your executable and rebuild it. Applying Windows XP visual style to controls The easiest way to learn to apply Windows XP visual style is to learn to do an example. At the end of this article, I will introduce you to any simple application and make the controls on its form have Windows XP visual style. Next, what we have to do is: Create a project that uses the program and add some controls to the form. Create a Manifest file and bundle the required DLL into your application. Store the Manifest file in the executable directory. Add a resource (Manifest file) to the executable file. Start creating a new project... Create a project: 1. Create a new Windows application project. (Note: Please remember the project name and the directory where the project is stored. Useful below) 2. Drag the following controls from the toolbox onto the form and arrange them: Button control RadioButton control ProgressBar control CheckBox control Label control (Note: Although the appearance of the Label control does not change, it is also dragged and dropped onto the form for Contrast) 3. Set the FlatStyle property of Button, RadioButton, CheckBox and other controls to System. (Tips: You can press the Ctrl key while clicking each control, so you can select these three controls at the same time. Then, select System in the drop-down box of the FlatStyle property.) Double-click the Button control to add an event handler to it, and the code editor will open automatically. 5. Add the following code to set the Value property of the ProgressBar control so that you can see a new progress bar: ' Visual Basic Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1. Click ProgressBar1.Value = 50 End Sub //C# private void button1_Click(object sender, System.EventArgs e) { progressBar1.Value = 50; } 6. Select the Build option from the Build menu. 7. Finally, save all. Create a Manifest file: Create an XML file and bundle the correct version of Comctl32.dll into your application. Create and edit a Manifest file: 1. In the Solution Explorer, right click on the project name: Add -> Add New Item 2. In the Add New Item dialog box, do the following: A. Click on "Local Project Item" in the box on the left. B. Select "Text File" in the box on the right. C. Name the file in the Name box as follows: .exe.manifest. Therefore, if your application is called MyXPApp, then you should name this XML file MyXPApp.exe.manifest. 3. Click the "Open" button and your new file will open in the text editor. 4. Add the following XML to the text file: version="1.0.0.0" processorArchitecture="X86" name="Microsoft.Winweb." type="win32"
Copyright © Windows knowledge All Rights Reserved