방법: 컨트롤 렌더링 클래스 사용

이 예제는 ComboBoxRenderer 클래스를 사용하여 콤보 상자 컨트롤의 드롭다운 화살표를 렌더링하는 방법을 보여 줍니다. 이 예제는 간단한 사용자 지정 컨트롤의 OnPaint 메서드로 구성됩니다. ComboBoxRenderer.IsSupported 속성은 애플리케이션 창의 클라이언트 영역에서 비주얼 스타일을 사용할 수 있는지 여부를 결정하는 데 사용됩니다. 비주얼 스타일이 활성 상태인 경우 ComboBoxRenderer.DrawDropDownButton 메서드가 비주얼 스타일을 사용하여 드롭다운 화살표를 렌더링하고, 그렇지 않은 경우 ControlPaint.DrawComboButton 메서드가 클래식 Windows 스타일로 드롭다운 화살표를 렌더링합니다.

예제

    // Render the drop-down arrow with or without visual styles.
protected:
    virtual void OnPaint(PaintEventArgs^ e) override
    {
        __super::OnPaint(e);

        if (!ComboBoxRenderer::IsSupported)
        {
            ControlPaint::DrawComboButton(e->Graphics,
                this->ClientRectangle, ButtonState::Normal);
        }
        else
        {
            ComboBoxRenderer::DrawDropDownButton(e->Graphics,
                this->ClientRectangle, ComboBoxState::Normal);
        }
    }
// Render the drop-down arrow with or without visual styles.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    if (!ComboBoxRenderer.IsSupported)
    {
        ControlPaint.DrawComboButton(e.Graphics,
            this.ClientRectangle, ButtonState.Normal);
    }
    else
    {
        ComboBoxRenderer.DrawDropDownButton(e.Graphics,
            this.ClientRectangle, ComboBoxState.Normal);
    }
}
' Render the drop-down arrow with or without visual styles.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)

    If Not ComboBoxRenderer.IsSupported Then
        ControlPaint.DrawComboButton(e.Graphics, _
            Me.ClientRectangle, ButtonState.Normal)
    Else
        ComboBoxRenderer.DrawDropDownButton(e.Graphics, _
            Me.ClientRectangle, ComboBoxState.Normal)
    End If
End Sub

코드 컴파일

이 예제에는 다음 사항이 필요합니다.

참고 항목