VisualStyleRenderer.IsElementDefined(VisualStyleElement) 方法

定义

确定当前视觉样式是否定义了指定的视觉样式元素。Determines whether the specified visual style element is defined by the current visual style.

public:
 static bool IsElementDefined(System::Windows::Forms::VisualStyles::VisualStyleElement ^ element);
public static bool IsElementDefined (System.Windows.Forms.VisualStyles.VisualStyleElement element);
static member IsElementDefined : System.Windows.Forms.VisualStyles.VisualStyleElement -> bool
Public Shared Function IsElementDefined (element As VisualStyleElement) As Boolean

参数

element
VisualStyleElement

将验证其类和部件组合的 VisualStyleElementA VisualStyleElement whose class and part combination will be verified.

返回

如果定义了 elementClassNamePart 属性的组合,则为 true;否则为 falsetrue if the combination of the ClassName and Part properties of element are defined; otherwise, false.

异常

操作系统不支持视觉样式。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.

示例

下面的代码示例演示如何使用 IsElementDefined 方法来确定是否将 VisualStyleRenderer 初始化为指定的 VisualStyleElementThe following code example demonstrates how to use the IsElementDefined method to determine whether to initialize a VisualStyleRenderer to a given VisualStyleElement. 此代码示例是为 VisualStyleRenderer 类概述提供的更大示例的一部分。This code example is part of a larger 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

注解

此方法在内部检查 IsSupported 属性的值。This method checks the value of the IsSupported property internally.

适用于