ComboBoxRenderer Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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 ref class ComboBoxRenderer sealed 


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.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::VisualStyles;

namespace ComboBoxRendererSample
    ref class CustomComboBox: public Control
        System::Drawing::Size arrowSize;
        Rectangle arrowRectangle;
        Rectangle topTextBoxRectangle;
        Rectangle bottomTextBoxRectangle;
        ComboBoxState textBoxState;
        ComboBoxState arrowState;
        String^ bottomText;
        bool isActivated;
        int minHeight;
        int minWidth;

        CustomComboBox() : Control()

              minHeight = 38;
              minWidth = 40; 
              this->Location = Point(10, 10);
              this->Size = System::Drawing::Size(140, 38);
              this->Font = SystemFonts::IconTitleFont;
              this->Text = "Click the button";
              textBoxState = ComboBoxState::Normal;
              bottomText = "Using ComboBoxRenderer";
              arrowState = ComboBoxState::Normal;

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

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

            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,

        virtual void OnMouseDown(MouseEventArgs^ e) override 

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

        virtual void OnMouseUp(MouseEventArgs^ e) override 

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

    ref class Form1 : public Form
        Form1() : Form()
            this->Size = System::Drawing::Size(300, 300);
            CustomComboBox^ ComboBox1 = gcnew CustomComboBox();



int 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(gcnew ComboBoxRendererSample::Form1());


.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