共用方式為


如何:使用控制項呈現類別

此範例示範如何使用 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

編譯程式碼

這個範例需要:

另請參閱