ComboBoxRenderer.DrawTextBox Method

Definition

Draws a text box with the current visual style of the operating system.

Overloads

DrawTextBox(Graphics, Rectangle, ComboBoxState)

Draws a text box in the specified state and bounds.

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

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

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

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

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

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

DrawTextBox(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.

DrawTextBox(Graphics, Rectangle, ComboBoxState)

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

Draws a text box in the specified state and bounds.

C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.ComboBoxState state);

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

state
ComboBoxState

One of the ComboBoxState values that specifies the visual state of the text box.

Exceptions

The operating system does not support visual styles.

-or-

Visual styles are disabled by the user in the operating system.

-or-

Visual styles are not applied to the client area of application windows.

Remarks

Before calling this method, you should verify that the IsSupported property returns true.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string comboBoxText, System.Drawing.Font font, System.Windows.Forms.VisualStyles.ComboBoxState state);
C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? comboBoxText, System.Drawing.Font? font, System.Windows.Forms.VisualStyles.ComboBoxState state);

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

comboBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to comboBoxText.

state
ComboBoxState

One of the ComboBoxState values that specifies the visual state of the text box.

Exceptions

The operating system does not support visual styles.

-or-

Visual styles are disabled by the user in the operating system.

-or-

Visual styles are not applied to the client area of application windows.

Remarks

Before calling this method, you should verify that the IsSupported property returns true.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string comboBoxText, System.Drawing.Font font, System.Drawing.Rectangle textBounds, System.Windows.Forms.VisualStyles.ComboBoxState state);
C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? comboBoxText, System.Drawing.Font? font, System.Drawing.Rectangle textBounds, System.Windows.Forms.VisualStyles.ComboBoxState state);

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

comboBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to comboBoxText.

textBounds
Rectangle

The Rectangle that specifies the bounds in which to draw comboBoxText.

state
ComboBoxState

One of the ComboBoxState values that specifies the visual state of the text box.

Exceptions

The operating system does not support visual styles.

-or-

Visual styles are disabled by the user in the operating system.

-or-

Visual styles are not applied to the client area of application windows.

Examples

The following code example uses the DrawTextBox(Graphics, Rectangle, String, Font, ComboBoxState) method in a custom control's OnPaint method to draw a text box. This code example is part of a larger example provided for the ComboBoxRenderer class.

C#
// Draw the combo box in the current state.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

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

    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,
        arrowState);

    // Only draw the bottom text box if the arrow has been clicked
    if (isActivated)
    {
        ComboBoxRenderer.DrawTextBox(e.Graphics,
            bottomTextBoxRectangle, bottomText, this.Font,
            textBoxState);
    }
}

protected override void OnMouseDown(MouseEventArgs e)
{
    base.OnMouseDown(e);

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

        // Redraw the control.
        Invalidate();
    }
}

Remarks

Before calling this method, you should verify that the IsSupported property returns true.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string comboBoxText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.ComboBoxState state);
C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? comboBoxText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.ComboBoxState state);

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

comboBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to comboBoxText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

state
ComboBoxState

One of the ComboBoxState values that specifies the visual state of the text box.

Exceptions

The operating system does not support visual styles.

-or-

Visual styles are disabled by the user in the operating system.

-or-

Visual styles are not applied to the client area of application windows.

Remarks

Before calling this method, you should verify that the IsSupported property returns true.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string comboBoxText, System.Drawing.Font font, System.Drawing.Rectangle textBounds, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.ComboBoxState state);
C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? comboBoxText, System.Drawing.Font? font, System.Drawing.Rectangle textBounds, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.ComboBoxState state);

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

comboBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to comboBoxText.

textBounds
Rectangle

The Rectangle that specifies the bounds in which to draw comboBoxText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

state
ComboBoxState

One of the ComboBoxState values that specifies the visual state of the text box.

Exceptions

The operating system does not support visual styles.

-or-

Visual styles are disabled by the user in the operating system.

-or-

Visual styles are not applied to the client area of application windows.

Remarks

Before calling this method, you should verify that the IsSupported property returns true.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10