TextBoxRenderer.DrawTextBox Method

Definition

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

Overloads

DrawTextBox(Graphics, Rectangle, TextBoxState)

Draws a text box control in the specified state and bounds.

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

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

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

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

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

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

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

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

DrawTextBox(Graphics, Rectangle, TextBoxState)

Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs

Draws a text box control in the specified state and bounds.

C#
public static void DrawTextBox(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.TextBoxState 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
TextBoxState

One of the TextBoxState 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 i druge verzije
Proizvod Verzije
.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, TextBoxState)

Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs

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

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

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

textBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to textBoxText.

state
TextBoxState

One of the TextBoxState 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 i druge verzije
Proizvod Verzije
.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, TextBoxState)

Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs

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

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

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

textBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to textBoxText.

textBounds
Rectangle

The Rectangle that specifies the bounds of textBoxText.

state
TextBoxState

One of the TextBoxState 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 i druge verzije
Proizvod Verzije
.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, TextBoxState)

Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs

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

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

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

textBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to textBoxText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

state
TextBoxState

One of the TextBoxState 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 i druge verzije
Proizvod Verzije
.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, TextBoxState)

Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs
Source:
TextBoxRenderer.cs

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

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

Parameters

g
Graphics

The Graphics used to draw the text box.

bounds
Rectangle

The Rectangle that specifies the bounds of the text box.

textBoxText
String

The String to draw in the text box.

font
Font

The Font to apply to textBoxText.

textBounds
Rectangle

The Rectangle that specifies the bounds of textBoxText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

state
TextBoxState

One of the TextBoxState 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 demonstrates how to use the DrawTextBox(Graphics, Rectangle, String, Font, Rectangle, TextFormatFlags, TextBoxState) 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 TextBoxRenderer class.

C#
// Use DrawText with the current TextFormatFlags.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    if (TextBoxRenderer.IsSupported)
    {
        TextBoxRenderer.DrawTextBox(e.Graphics, textBorder, this.Text,
            this.Font, textRectangle, textFlags, TextBoxState.Normal);

        this.Parent.Text = "CustomTextBox Enabled";
    }
    else
    {
        this.Parent.Text = "CustomTextBox Disabled";
    }
}

Remarks

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

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.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