--- title: "Rendering Controls with Visual Styles" ms.date: "03/30/2017" helpviewer_keywords: - "professional appearance [Windows Forms], rendering Windows Forms controls" - "themes [Windows Forms], XP visual styles in Window Forms" - "custom controls [Windows Forms], rendering" - "custom controls [Windows Forms], painting" - "visual themes [Windows Forms], rendering Windows Forms controls" - "user controls [Windows Forms], painting" - "visual styles [Windows Forms], rendering Windows Forms controls" ms.assetid: a5b178ba-610e-46c4-a6c0-509c0886a744 --- # Rendering Controls with Visual Styles The .NET Framework provides support for rendering controls and other Windows user interface (UI) elements using visual styles in operating systems that support them. This topic discusses the several levels of support in the .NET Framework for rendering controls and other UI elements with the current visual style of the operating system. ## Rendering Classes for Common Controls Rendering a control refers to drawing the user interface of a control. The namespace provides the class for rendering some common Windows Forms controls. However, this class draws controls in the classic Windows style, which can make it difficult to maintain a consistent UI experience when drawing custom controls in applications with visual styles enabled. The .NET Framework 2.0 includes classes in the namespace that render the parts and states of common controls with visual styles. Each of these classes includes `static` methods for drawing the control or parts of the control in a particular state with the current visual style of the operating system. Some of these classes are designed to draw the related control regardless of whether visual styles are available. If visual styles are enabled, then the class members will draw the related control with visual styles; if visual styles are disabled, then the class members will draw the control in the classic Windows style. These classes include: - - - - Other classes can only draw the related control when visual styles are available, and their members will throw an exception if visual styles are disabled. These classes include: - - - - - - For more information on using these classes to draw a control, see [How to: Use a Control Rendering Class](how-to-use-a-control-rendering-class.md). ## Visual Style Element and Rendering Classes The namespace includes classes that can be used to draw and get information about any control or UI element that is supported by visual styles. Supported controls include common controls that have a rendering class in the namespace (see the previous section), as well as other controls, such as tab controls and rebar controls. Other supported UI elements include the parts of the **Start** menu, the taskbar, and the nonclient area of windows. The main classes of the namespace are and . is a foundation class for identifying any control or user interface element supported by visual styles. In addition to itself, the namespace includes many nested classes of with `static` properties that return a for every state of a control, control part, or other UI element supported by visual styles. provides the methods that draw and get information about each defined by the current visual style of the operating system. Information that can be retrieved about an element includes its default size, background type, and color definitions. wraps the functionality of the visual styles (UxTheme) API from the Windows Shell portion of the Windows Platform SDK. For more information, see [Enabling Visual Styles](/windows/desktop/controls/cookbook-overview). For more information about using and , see [How to: Render a Visual Style Element](how-to-render-a-visual-style-element.md). ## Enabling Visual Styles To enable visual styles for an application written for the .NET Framework version 1.0, programmers must include an application manifest that specifies that ComCtl32.dll version 6 or later will be used to draw controls. Applications built with the .NET Framework version 1.1 or later can use the method of the class. ## Checking for Visual Styles Support The property of the class indicates whether the current application is drawing controls with visual styles. When painting a custom control, you can check the value of to determine whether you should render your control with or without visual styles. The following table lists the four conditions that must exist for to return `true`. |Condition|Notes| |---------------|-----------| |The operating system supports visual styles.|To verify this condition separately, use the property of the class.| |The user has enabled visual styles in the operating system.|To verify this condition separately, use the property of the class.| |Visual styles are enabled in the application.|Visual styles can be enabled in an application by calling the method or by using an application manifest that specifies that ComCtl32.dll version 6 or later will be used to draw controls.| |Visual styles are being used to draw the client area of application windows.|To verify this condition separately, use the property of the class and verify that it has the value or .| To determine when a user enables or disables visual styles, or switches from one visual style to another, check for the value in the handlers for the or events. > [!IMPORTANT] > If you want to use to render a control or UI element when the user enables or switches visual styles, make sure that you do this when handling the event instead of the event. An exception will be thrown if you use the class when handling . ## See also - [Custom Control Painting and Rendering](custom-control-painting-and-rendering.md)