Export (0) Print
Expand All

How to: Use a Control Rendering Class

This example demonstrates how to use the ComboBoxRenderer class to render the drop-down arrow of a combo box control. The example consists of the OnPaint method of a simple custom control. The ComboBoxRenderer.IsSupported property is used to determine whether visual styles are enabled in the client area of application windows. If visual styles are active, then the ComboBoxRenderer.DrawDropDownButton method will render the drop-down arrow with visual styles; otherwise, the ControlPaint.DrawComboButton method will render the drop-down arrow in the classic Windows style.

// 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);
    }
}

This example requires:

Show:
© 2014 Microsoft