Редагувати

Поділитися через


VisualStyleRenderer Constructors

Definition

Initializes a new instance of the VisualStyleRenderer class.

Overloads

VisualStyleRenderer(VisualStyleElement)

Initializes a new instance of the VisualStyleRenderer class using the given VisualStyleElement.

VisualStyleRenderer(String, Int32, Int32)

Initializes a new instance of the VisualStyleRenderer class using the given class, part, and state values.

VisualStyleRenderer(VisualStyleElement)

Initializes a new instance of the VisualStyleRenderer class using the given VisualStyleElement.

public:
 VisualStyleRenderer(System::Windows::Forms::VisualStyles::VisualStyleElement ^ element);
public VisualStyleRenderer (System.Windows.Forms.VisualStyles.VisualStyleElement element);
new System.Windows.Forms.VisualStyles.VisualStyleRenderer : System.Windows.Forms.VisualStyles.VisualStyleElement -> System.Windows.Forms.VisualStyles.VisualStyleRenderer
Public Sub New (element As VisualStyleElement)

Parameters

element
VisualStyleElement

A VisualStyleElement that this VisualStyleRenderer will represent.

Exceptions

The operating system does not support visual styles.

-or-

Visual styles are disabled by the user in the operating system.

-or-

Visual styles are not applied to the client area of application windows.

element is not defined by the current visual style.

Examples

The following code example demonstrates how to use the VisualStyleRenderer(VisualStyleElement) constructor to create a VisualStyleRenderer. This code example is part of a larger code example provided for the VisualStyleRenderer class overview.

    // Set the VisualStyleRenderer to a new element.
private:
    bool SetRenderer(VisualStyleElement^ element)
    {
        if (!VisualStyleRenderer::IsElementDefined(element))
        {
            return false;
        }

        if (renderer == nullptr)
        {
            renderer = gcnew VisualStyleRenderer(element);
        }
        else
        {
            renderer->SetParameters(element);
        }

        return true;
    }
// Set the VisualStyleRenderer to a new element.
private bool SetRenderer(VisualStyleElement element)
{
    if (!VisualStyleRenderer.IsElementDefined(element))
    {
        return false;
    }

    if (renderer == null)
    {
        renderer = new VisualStyleRenderer(element);
    }
    else
    {
        renderer.SetParameters(element);
    }

    return true;
}
' Set the VisualStyleRenderer to a new element.
Private Function SetRenderer(ByVal element As _
    VisualStyleElement) As Boolean

    If Not VisualStyleRenderer.IsElementDefined(element) Then
        Return False
    End If

    If renderer Is Nothing Then
        renderer = New VisualStyleRenderer(element)
    Else
        renderer.SetParameters(element)
    End If

    Return True
End Function

Remarks

This constructor uses the VisualStyleElement.ClassName, VisualStyleElement.Part, and VisualStyleElement.State properties of the element parameter to initialize the Class, Part, and State properties.

Before using this constructor, you should call the static IsElementDefined method to verify whether the current visual style provides a definition for the element specified by the element parameter.

Applies to

VisualStyleRenderer(String, Int32, Int32)

Initializes a new instance of the VisualStyleRenderer class using the given class, part, and state values.

public:
 VisualStyleRenderer(System::String ^ className, int part, int state);
public VisualStyleRenderer (string className, int part, int state);
new System.Windows.Forms.VisualStyles.VisualStyleRenderer : string * int * int -> System.Windows.Forms.VisualStyles.VisualStyleRenderer
Public Sub New (className As String, part As Integer, state As Integer)

Parameters

className
String

The class name of the element that this VisualStyleRenderer will represent.

part
Int32

The part of the element that this VisualStyleRenderer will represent.

state
Int32

The state of the element that this VisualStyleRenderer will represent.

Exceptions

The operating system does not support visual styles.

-or-

Visual styles are disabled by the user in the operating system.

-or-

Visual styles are not applied to the client area of application windows.

The combination of className, part, and state is not defined by the current visual style.

.NET 5 and later: className is null.

Remarks

This constructor uses the className, part, and state parameters to initialize the Class, Part, and State properties.

Before using this constructor, you should call the static IsElementDefined method to verify whether the current visual style provides a definition for the element specified by the className, part, and state parameters.

Applies to