Partager via


Comment utiliser une classe de rendu de contrôles

Cet exemple montre comment utiliser la classe ComboBoxRenderer pour afficher la flèche déroulante d’une zone de liste modifiable. L’exemple se compose de la méthode OnPaint d’un contrôle personnalisé simple. La propriété ComboBoxRenderer.IsSupported est utilisée pour déterminer si les styles visuels sont activés dans la zone cliente des fenêtres d’application. Si les styles visuels sont actifs, la méthode ComboBoxRenderer.DrawDropDownButton affiche la flèche déroulante avec des styles visuels ; sinon, la méthode ControlPaint.DrawComboButton affiche la flèche déroulante dans le style Windows classique.

Exemple :

    // 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

Compilation du code

Cet exemple nécessite :

Voir aussi