Anzeigen von Formularen mit Windows XP Visual Styles
Anzeigen von Formularen mit Windows XP Visual Styles <URL:http://dotnet.mvps.org/dotnet/faqs/?id=xpvisualstyles&lang=de> ---------------------------------------------------------------------------- Enabling Windows XP Visual Styles for Windows Forms applications General information about visual styles can be found in this article: Using Windows XP Visual Styles <URL:http://msdn.microsoft.com/library/en-us/dnwxp/html/xptheming.asp> To enable visual styles for Windows Forms controls in .NET 1.0 and .NET 1.1, set the controls' 'FlatStyle' properties to 'System'. Note that some style features such as button images are not available in this mode. Some controls cannot be displayed with visual styles in .NET 1.0/1.1. The NumericUpDown control does not support visual styles at all, and the TabControl fills tabpages instead of keeping their background transparent: Get the real XP look with Tab Pages <URL:http://www.codeproject.com/cs/miscctrl/themedtabpage.asp> These bugs are fixed in .NET 2.0. Button controls rendered in the 'System' mode do not support theming if an image is shown on the button. There are workarounds available: <URL:http://dotnetrix.co.uk/buttons.html> -> "Windows XP themed buttons don't show an Image." -> "Windows XP themed buttons don't show an Image (an alternative method)." XP-Style Button <URL:http://www.codeproject.com/cs/miscctrl/xp-style_button.asp> .NET 1.0: This version of the .NET Framework does not provide support for visual styles. In order to enable visual styles, an application manifest is required. Manifest files are special XML files. There are two ways for associating a manifest file with an executable. The simplest method is to create a manifest with the name of the executable and append ".manifest" to its name. For example, the executable name "Foo.exe" will lead to a manifest named "Foo.exe.manifest". This file must be placed in the same folder as the executable file. The other method, which is more complicated than the first one, is to embed the manifest file as a resource into the executable's Win32 resources. The manifest file needs no be stored as a resource of type 'RT_MANIFEST'. Visual Studio 6 and Visual Studio .NET support editing the unmanaged resources of a binary file. Nevertheless, the manifest has to be added after every compilation process which will take a lot of effort. Mattias Sjögren [MVP] has written a command line tool in C# that can be used to embed an application manifest into the executable file as a Win32 resource: <URL:http://www.msjogren.net/dotnet/eng/tools/> -> "ThemeMe" An alternative implementation that is available as VB.NET source code can be found here: ThemeUtil <URL:http://dotnet.mvps.org/dotnet/samples/tools/#Win32Res> There is a VS.NET addin available that provides support for visual styles during the development process: Creating a Visual Studio .NET Add-In to Provide Windows XP Theme Support <URL:http://msdn.microsoft.com/library/en-us/dnwinforms/html/xpthemeaddin_.asp> Using Windows XP Visual Styles With Controls on Windows Forms <URL:http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbtchUsingWindowsXPVisualStylesWithControlsOnWindowsForms.asp> .NET 1.1: This version of .NET natively supports visual styles through 'Application.EnableVisualStyles'. An overview of enhancements in Windows Forms in .NET 1.1 and visual styles can be found here: .NET Framework 1.1 Provides Expanded Namespace, Security, and Language Support for Your Projects <URL:http://msdn.microsoft.com/msdnmag/issues/03/03/WindowsForms/> Typically, 'EnableVisualStyles' should be called prior to showing any form, for example, in the application's 'Sub Main': \\\ Application.EnableVisualStyle() Application.DoEvents() ' Bug fix. /// 'Application.EnableVisualStyles' Bug <URL:http://www.codeproject.com/buglist/EnableVisualStylesBug.asp> You receive an "unhandled exception of type 'System.Runtime.InteropServices.SEHException'" error message when you call the 'Application.EnableVisualStyles' method in Visual Basic .NET 2003 and in Visual Basic 2002 <URL:http://support.microsoft.com/?scid=kb;EN-US;897298> Visual styles support in .NET 1.1 is buggy. Microsoft has confirmed that several times in newsgroups and forums: <URL:http://windowsforms.net/Forums/ShowPost.aspx?tabIndex=1&tabId=41&PostID=604> Enabling visual styles in .NET 1.1 can cause exceptions of type 'SEHException' to be thrown and icons in toolbars, listviews, treeviews, and other common controls to disappear. .NET 2.0: In .NET 2.0 visual styles will be applied to most controls when the 'Standard' flat style is selected. There will be full support for Windows XP visual styles for almost all Windows Forms controls. In Visual Basic 2005 visual styles can be enabled as part of the Windows Application Framework ("My Project" -> "Application" -> "Windows application framework properties" -> [X] "Enable XP visual styles". Additionally a managed wrapper around the unmanaged visual styles API is provided in the 'System.Windows.Forms.VisualStyles' namespace.