Default XP Theme support?

T

Terry Olsen

I paste the following code into each project to get XP theme support.
'Add this at the beginning of any program to enable Windows XP Visual Styles
<System.STAThread()> Public Shared Sub Main()
If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
System.Windows.Forms.Application.EnableVisualStyles()
End If
Application.DoEvents() 'This must be here, otherwise buttons won't
stylize
System.Windows.Forms.Application.Run(New Form1)
End Sub 'Main

Is there a way I can set up the VS IDE to automatically put this code in
each form's code?
 
K

Ken Tucker [MVP]

Hi,

http://support.microsoft.com/default.aspx?scid=kb;en-us;555160

Ken
------------------------
I paste the following code into each project to get XP theme support.
'Add this at the beginning of any program to enable Windows XP Visual Styles
<System.STAThread()> Public Shared Sub Main()
If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
System.Windows.Forms.Application.EnableVisualStyles()
End If
Application.DoEvents() 'This must be here, otherwise buttons won't
stylize
System.Windows.Forms.Application.Run(New Form1)
End Sub 'Main

Is there a way I can set up the VS IDE to automatically put this code in
each form's code?
 
H

Herfried K. Wagner [MVP]

Terry Olsen said:
I paste the following code into each project to get XP theme support.
'Add this at the beginning of any program to enable Windows XP Visual
Styles
<System.STAThread()> Public Shared Sub Main()
If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
System.Windows.Forms.Application.EnableVisualStyles()
End If
Application.DoEvents() 'This must be here, otherwise buttons won't
stylize
System.Windows.Forms.Application.Run(New Form1)
End Sub 'Main

Is there a way I can set up the VS IDE to automatically put this code in
each form's code?

You can put the code in your app's main class and don't need it in every
form.
 
J

Jim Burns

There is a .Manifest you can put in the same Dir as the exe and you will get
support.
even better you open the exe in Visual studio and add it as a resources ill
post the manifest with instructions for both.
 
J

Jim Burns

Windows Forms: XP Theme Support
Demonstrates how to enables support for XP themes in your application.
Featured Highlights:
To enable XP theme support in your application you have to write very little
code. The main task is to create a manifest file and associate it with your
application.
At this point controls that support XP Themes will appear "themed" in your
application.

This application displays three tabs that highlight the following:

Controls that support Visual Themes without any changes to property settings
Three controls that support visual styles but which are not
demonstrated on this form are H ScrollBar and
V ScrollBar, and the TrackBar control.
Controls that require the flatStyle property to be set to system.
Certain controls that do not support themes or that have limited support are
also demonstrated.

Requirements:
Microsoft Visual Studio.NET Professional or greater.
Windows XP Home or Professional

Running the Sample:
Simply press F5.

Note: The application contains only static data and controls as the only
purpose of this sample is to demonstrate the use of Themes.

If you want to create your own Windows Forms application here are the steps
you will have to perform:

Set each control with a FlatStyle property to FlatStyle.System

Create a manifest file to bind your app to comctl6. The sample manifest file
below can be used to bind any app (managed or unmanaged) to comctl6. Just
copy it to the location of the .exe and rename it to <app
name>.exe.manifest.

You must then add a Win32 resource to your application. This is
accomplished by first opening up the *.exe.

1. Open your exe in VS (file -> open file)
2. Right click on it and select add resource
3. Click "Import..." from the dialog
4. Select your manifest file
5. In the "Resource Type" field, enter "RT_MANIFEST"
6. In the property grid, change the resource ID from "101" to "1".
7. Save the exe.
8. Make sure the manifest is keep at the same directory level as the
executable. (In this How-To it is placed in the bin directory of the
solution)

A sample manifest is also included and is named Sample_Manifest.xml.



Here is the Manifest

Cut-------------------------------------------------------------------------
------------------------------------------------

<?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="Your
App name here" type

="win32" />
<description>.NET control deployment tool</description>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"

processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"
/>
</dependentAssembly>
</dependency>
</assembly>

End
cut-------------------------------------------------------------------------
 
J

Jim Burns

Sorry left something out.
copy the file between the cut and end cut line.
then past into notepad Save file as "Your app name.exe.manifest"
you will not get them support in the IDE but you will get it when you run
your exe.
on the previous post there were two way to add the file I always add it to
the exe as a resources this way the end user cant delete it. or if its stand
alone exe it can be moved to any Dir.and still have theme support.
 
J

Jim Burns

I guess I don get it.
every app done on vb.net ,I've done just gets form support.
I change the theme on my computer and the apps form changes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top