ComboBoxRenderer Class
Collapse the table of content
Expand the table of content

ComboBoxRenderer Class


Provides methods used to render a combo box control with visual styles. This class cannot be inherited.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)


public sealed class ComboBoxRenderer


Gets a value indicating whether the ComboBoxRenderer class can be used to draw a combo box with visual styles.

System_CAPS_pubmethodSystem_CAPS_staticDrawDropDownButton(Graphics, Rectangle, ComboBoxState)

Draws a drop-down arrow with the current visual style of the operating system.

System_CAPS_pubmethodSystem_CAPS_staticDrawTextBox(Graphics, Rectangle, ComboBoxState)

Draws a text box in the specified state and bounds.

System_CAPS_pubmethodSystem_CAPS_staticDrawTextBox(Graphics, Rectangle, String, Font, ComboBoxState)

Draws a text box in the specified state and bounds, with the specified text.

System_CAPS_pubmethodSystem_CAPS_staticDrawTextBox(Graphics, Rectangle, String, Font, Rectangle, ComboBoxState)

Draws a text box in the specified state and bounds, with the specified text and text bounds.

System_CAPS_pubmethodSystem_CAPS_staticDrawTextBox(Graphics, Rectangle, String, Font, Rectangle, TextFormatFlags, ComboBoxState)

Draws a text box in the specified state and bounds, with the specified text, text formatting, and text bounds.

System_CAPS_pubmethodSystem_CAPS_staticDrawTextBox(Graphics, Rectangle, String, Font, TextFormatFlags, ComboBoxState)

Draws a text box in the specified state and bounds, with the specified text and text formatting.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

The ComboBoxRenderer class provides a set of static methods that can be used to render a combo box control with the current visual style of the operating system. Rendering a control refers to drawing the user interface of a control. This is useful if you are drawing a custom control that should have the appearance of the current visual style. To draw a combo box, use the DrawTextBox method to draw the text box and the DrawDropDownButton method to draw the drop-down arrow.

If visual styles are enabled in the operating system and visual styles are applied to the client area of application windows, DrawTextBox and DrawDropDownButton will draw the combo box with the current visual style. Otherwise, these methods will throw an InvalidOperationException. To determine whether the members of this class can be used, you can check the value of the IsSupported property.

This class wraps the functionality of a System.Windows.Forms.VisualStyles.VisualStyleRenderer that is set to one of the elements exposed by the System.Windows.Forms.VisualStyles.VisualStyleElement.ComboBox.DropDownButton and System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox.TextEdit classes. For more information, see Rendering Controls with Visual Styles.


Visual styles are supported only on these platforms.

The following code example demonstrates how to create a custom control that uses the DrawTextBox and DrawDropDownButton methods to draw a combo box that responds to mouse clicks.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace ComboBoxRendererSample
    class Form1 : Form
        public Form1()
            : base()
            this.Size = new Size(300, 300);
            CustomComboBox ComboBox1 = new CustomComboBox();

        static void Main()
            // The call to EnableVisualStyles below does not affect
            // whether ComboBoxRenderer.IsSupported is true; as long as visual
            // styles are enabled by the operating system, IsSupported is true.
            Application.Run(new Form1());

    public class CustomComboBox : Control
        private Size arrowSize;
        private Rectangle arrowRectangle;
        private Rectangle topTextBoxRectangle;
        private Rectangle bottomTextBoxRectangle;
        private ComboBoxState textBoxState = ComboBoxState.Normal;
        private ComboBoxState arrowState = ComboBoxState.Normal;
        private String bottomText = "Using ComboBoxRenderer";
        private bool isActivated = false;
        private const int minHeight = 38;
        private const int minWidth = 40;

        public CustomComboBox()
            : base()
            this.Location = new Point(10, 10);
            this.Size = new Size(140, 38);
            this.Font = SystemFonts.IconTitleFont;
            this.Text = "Click the button";

            // Initialize the rectangles to look like the standard combo 
            // box control.
            arrowSize = new Size(18, 20);
            arrowRectangle = new Rectangle(ClientRectangle.X +
                ClientRectangle.Width - arrowSize.Width - 1,
                ClientRectangle.Y + 1,
            topTextBoxRectangle = new Rectangle(ClientRectangle.X,
                arrowSize.Height + 2);
            bottomTextBoxRectangle = new Rectangle(ClientRectangle.X,
                ClientRectangle.Y + topTextBoxRectangle.Height,
                topTextBoxRectangle.Height - 6);

        // Draw the combo box in the current state.
        protected override void OnPaint(PaintEventArgs e)

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

            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,

            // Only draw the bottom text box if the arrow has been clicked
            if (isActivated)
                    bottomTextBoxRectangle, bottomText, this.Font,

        protected override void OnMouseDown(MouseEventArgs e)

            // Check whether the user clicked the arrow.
            if (arrowRectangle.Contains(e.Location) &&
                // 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.
                    this.Text = "Click here";
                    textBoxState = ComboBoxState.Normal;
                    isActivated = false;

                // Redraw the control.

        protected override void OnMouseUp(MouseEventArgs e)

            if (arrowRectangle.Contains(e.Location) &&
                arrowState = ComboBoxState.Normal;

.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft