ComboBoxRenderer.DrawDropDownButton Metodo

Definizione

Disegna una freccia a discesa con lo stile di visualizzazione corrente del sistema operativo.

public:
 static void DrawDropDownButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::VisualStyles::ComboBoxState state);
public static void DrawDropDownButton (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.ComboBoxState state);
static member DrawDropDownButton : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.ComboBoxState -> unit
Public Shared Sub DrawDropDownButton (g As Graphics, bounds As Rectangle, state As ComboBoxState)

Parametri

g
Graphics

Oggetto Graphics utilizzato per disegnare la freccia a discesa.

bounds
Rectangle

Oggetto Rectangle che specifica i limiti della freccia a discesa.

state
ComboBoxState

Uno dei valori ComboBoxState che specifica lo stato di visualizzazione della freccia a discesa.

Eccezioni

Il sistema operativo non supporta gli stili di visualizzazione.

-oppure-

Gli stili di visualizzazione sono stati disabilitati dall'utente nel sistema operativo.

-oppure-

Gli stili di visualizzazione non sono stati applicati all'area client delle finestre dell'applicazione.

Esempio

Nell'esempio di codice seguente viene utilizzato il DrawDropDownButton metodo nel metodo di OnPaint un controllo personalizzato per disegnare una freccia a discesa nello stato determinato dalla posizione del puntatore del mouse. Questo esempio di codice fa parte di un esempio più ampio fornito per la ComboBoxRenderer classe .

      // Draw the combo box in the current state.
protected:
    virtual void OnPaint(PaintEventArgs^ e) override 
    {
        Control::OnPaint(e);

        if (!ComboBoxRenderer::IsSupported)
        {
            this->Parent->Text = "Visual Styles Disabled";
            return;
        }

        this->Parent->Text = "CustomComboBox Enabled";

        // Always draw the main text box and drop down arrow in their
        // current states
        ComboBoxRenderer::DrawTextBox(e->Graphics, topTextBoxRectangle,
            this->Text, this->Font, textBoxState);
        ComboBoxRenderer::DrawDropDownButton(e->Graphics, arrowRectangle,
            arrowState);

        // Only draw the bottom text box if the arrow has been clicked
        if (isActivated)
        {
            ComboBoxRenderer::DrawTextBox(e->Graphics,
                bottomTextBoxRectangle, bottomText, this->Font,
                textBoxState);
        }
    }

protected:
    virtual void OnMouseDown(MouseEventArgs^ e) override 
    {
        Control::OnMouseDown(e);

        // Check whether the user clicked the arrow.
        if (arrowRectangle.Contains(e->Location) &&
            ComboBoxRenderer::IsSupported)
        {
            // Draw the arrow in the pressed state.
            arrowState = ComboBoxState::Pressed;

            // The user has activated the combo box.
            if (!isActivated)
            {
                this->Text = "Clicked!";
                textBoxState = ComboBoxState::Pressed;
                isActivated = true;
            }

            // The user has deactivated the combo box.
            else
            {
                this->Text = "Click here";
                textBoxState = ComboBoxState::Normal;
                isActivated = false;
            }

            // Redraw the control.
            Invalidate();
        }
    }
// Draw the combo box in the current state.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    if (!ComboBoxRenderer.IsSupported)
    {
        this.Parent.Text = "Visual Styles Disabled";
        return;
    }

    this.Parent.Text = "CustomComboBox Enabled";

    // Always draw the main text box and drop down arrow in their 
    // current states
    ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle,
        this.Text, this.Font, textBoxState);
    ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle,
        arrowState);

    // Only draw the bottom text box if the arrow has been clicked
    if (isActivated)
    {
        ComboBoxRenderer.DrawTextBox(e.Graphics,
            bottomTextBoxRectangle, bottomText, this.Font,
            textBoxState);
    }
}

protected override void OnMouseDown(MouseEventArgs e)
{
    base.OnMouseDown(e);

    // Check whether the user clicked the arrow.
    if (arrowRectangle.Contains(e.Location) &&
        ComboBoxRenderer.IsSupported)
    {
        // Draw the arrow in the pressed state.
        arrowState = ComboBoxState.Pressed;

        // The user has activated the combo box.
        if (!isActivated)
        {
            this.Text = "Clicked!";
            textBoxState = ComboBoxState.Pressed;
            isActivated = true;
        }

        // The user has deactivated the combo box.
        else
        {
            this.Text = "Click here";
            textBoxState = ComboBoxState.Normal;
            isActivated = false;
        }

        // Redraw the control.
        Invalidate();
    }
}
' Draw the combo box in the current state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)

    If Not ComboBoxRenderer.IsSupported Then
        Me.Parent.Text = "Visual Styles	Disabled"
        Return
    End If

    Me.Parent.Text = "CustomComboBox Enabled"

    ' Always draw the main text box and drop down arrow in their 
    ' current states.
    ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle, _
        Me.Text, Me.Font, textBoxState)
    ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle, _
        arrowState)

    ' Only draw the bottom text box if the arrow has been clicked.
    If isActivated Then
        ComboBoxRenderer.DrawTextBox(e.Graphics, _
            bottomTextBoxRectangle, bottomText, Me.Font, textBoxState)
    End If
End Sub

Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
    MyBase.OnMouseDown(e)

    ' Check whether the user clicked the arrow.
    If arrowRectangle.Contains(e.Location) And _
        ComboBoxRenderer.IsSupported Then

        ' Draw the arrow in the pressed state.
        arrowState = ComboBoxState.Pressed

        ' The user has activated the combo box.
        If Not isActivated Then
            Me.Text = "Clicked!"
            textBoxState = ComboBoxState.Pressed
            isActivated = True

        ' The user has deactivated the combo box.
        Else
            Me.Text = "Click here"
            textBoxState = ComboBoxState.Normal
            isActivated = False
        End If

        ' Redraw the control.
        Invalidate()
    End If
End Sub

Commenti

Prima di chiamare questo metodo, è necessario verificare che la IsSupported proprietà restituisca true.

Si applica a