The VisualStyleElement class identifies a Windows control or user interface (UI) element that is defined by the current visual style of the operating system. A visual style element is defined in terms of class, part, and state:

The class identifies a group of related visual style elements that are typically drawn together. The class is specified by the ClassName property.

The part defines a discrete member of a class. The part is specified by the Part property.

The state describes the current visual state of the element defined by the class and part. The state is specified by the State property.

The System.Windows.Forms.VisualStyles namespace exposes hundreds of VisualStyleElement objects that represent the controls and user interface elements that can be defined by a visual style. These objects are exposed as static properties of nested classes of VisualStyleElement. For each property, the qualified name of the owning class represents the class and the part of the drawn element, and the property name represents the state of the element. For example, the VisualStyleElement.Button.PushButton.Pressed property returns a VisualStyleElement that can be used to draw a button in the pressed state with visual styles. The Pressed property name corresponds to the state, PushButton corresponds to the part, and Button identifies the class of the visual style element.

To draw a visual style element, create a VisualStyleRenderer, set it to the VisualStyleElement you wish to draw, and then call the DrawBackground method. To determine whether the current visual style provides a definition for a particular element, call the IsElementDefined method with the element as the argument.

VisualStyleElement and VisualStyleRenderer wrap the functionality of the visual styles API from the Windows Shell portion of the Windows Platform SDK. For more information on visual styles, see "Using Windows XP Visual Styles" in the Platform SDK portion of the MSDN Library at http://msdn.microsoft.com/library.

The following code example is a complete application that provides a UI for browsing and drawing all of the VisualStyleElement objects exposed by the System.Windows.Forms.VisualStyles namespace. To view an element, use the ListView control on the left side of the window to navigate to the node that represents the state of the element you want to draw, and then click the node. This sample will draw the selected element only if the element is defined by the current visual style.