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 System.Windows.Forms.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 System.Windows.Forms.ComboBoxRenderer.DrawDropDownButton(System.Drawing.Graphics,System.Drawing.Rectangle,System.Windows.Forms.VisualStyles.ComboBoxState) method will render the drop-down arrow with visual styles; otherwise, the System.Windows.Forms.ControlPaint.DrawComboButton method will render the drop-down arrow in the classic Windows style.

Example

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

Compiling the Code

This example requires:

See Also

Community Additions

ADD
Show:
© 2014 Microsoft