Subscribe

RSS Feed (xml)

Apply Windows XP Control Styles

Windows XP styles are automatically applied to non-client areas of a form (such as the border and the minimize and maximize buttons). However, they won't be applied to controls such as buttons and group boxes unless you take additional steps.

First of all, you must configure all your form's button-style controls (such as buttons, check boxes, and radio buttons). These controls provide a FlatStyle property, which must be set to System.

The next step depends on the version of .NET that you are using. If you are using the .NET Framework version 1.1, you simply need to call the Application.EnableVisualStyles method before you show any forms. For example, you can start your application with the Main method shown here:

public static void Main() {

    // Enable visual styles.
    Application.EnableVisualStyles();

    // Show the main form for your application.
    Application.Run(new StartForm)
}

If you are using the .NET Framework version 1.0, you don't have the convenience of the Application.EnableVisualStyles method. However, you can still use visual styles-you simply need to create a manifest file for your application. This manifest file (an ordinary text file with XML content) tells Windows XP that your application requires the new version of the Comctl32.dll file. This file, which defines the new control styles, is included on all Windows XP computers. Windows XP will read and apply the settings from the manifest file automatically, provided you deploy it in the application directory and give it the correct name. The manifest file should have the same name as the executable used for your application, plus the extension .manifest (so TheApp.exe would have the manifest file TheApp.exe.manifest-even though this looks like two extensions).

Following is a sample manifest file. You can copy this file for your own applications-just rename it accordingly. It's also recommended that you modify the name value to use your application name, although this step isn't necessary.

<?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="TheApp" 
    type="win32" /> 

<dependency> 
<dependentAssembly> 
<assemblyIdentity 
    type="win32" 
    name="Microsoft.Windows.Common-Controls" 
    version="6.0.0.0" 
    processorArchitecture="X86" 
    publicKeyToken="6595b64144ccf1df" 
    language="*" /> 

</dependentAssembly> 
</dependency> 
</assembly>

The Windows XP styles won't appear in the Visual Studio .NET design- time environment. To test that this technique is working, run the application. Below Figure shows the difference between the Windows XP and non-Windows XP control styles.

windows-xp.JPG

No comments:

Post a Comment

Archives

LocalsAdda.com-Variety In Web World

Fun Mail - Fun in the Mail