Bearbeiten

Teilen über


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)

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

public:
 static void DrawTextBox(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::VisualStyles::TextBoxState state);
public static void DrawTextBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.TextBoxState state);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.TextBoxState -> unit
Public Shared Sub DrawTextBox (g As Graphics, bounds As Rectangle, state As TextBoxState)

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

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

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

public:
 static void DrawTextBox(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ textBoxText, System::Drawing::Font ^ font, System::Windows::Forms::VisualStyles::TextBoxState state);
public static void DrawTextBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string textBoxText, System.Drawing.Font font, System.Windows.Forms.VisualStyles.TextBoxState state);
public static void DrawTextBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? textBoxText, System.Drawing.Font? font, System.Windows.Forms.VisualStyles.TextBoxState state);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.VisualStyles.TextBoxState -> unit
Public Shared Sub DrawTextBox (g As Graphics, bounds As Rectangle, textBoxText As String, font As Font, state As TextBoxState)

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

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.

public:
 static void DrawTextBox(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ textBoxText, System::Drawing::Font ^ font, System::Drawing::Rectangle textBounds, System::Windows::Forms::VisualStyles::TextBoxState state);
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);
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);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.TextBoxState -> unit
Public Shared Sub DrawTextBox (g As Graphics, bounds As Rectangle, textBoxText As String, font As Font, textBounds As Rectangle, state As TextBoxState)

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

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.

public:
 static void DrawTextBox(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ textBoxText, System::Drawing::Font ^ font, System::Windows::Forms::TextFormatFlags flags, System::Windows::Forms::VisualStyles::TextBoxState state);
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);
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);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.TextFormatFlags * System.Windows.Forms.VisualStyles.TextBoxState -> unit
Public Shared Sub DrawTextBox (g As Graphics, bounds As Rectangle, textBoxText As String, font As Font, flags As TextFormatFlags, state As TextBoxState)

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

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.

public:
 static void DrawTextBox(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::String ^ textBoxText, System::Drawing::Font ^ font, System::Drawing::Rectangle textBounds, System::Windows::Forms::TextFormatFlags flags, System::Windows::Forms::VisualStyles::TextBoxState state);
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);
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);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Drawing.Rectangle * System.Windows.Forms.TextFormatFlags * System.Windows.Forms.VisualStyles.TextBoxState -> unit
Public Shared Sub DrawTextBox (g As Graphics, bounds As Rectangle, textBoxText As String, font As Font, textBounds As Rectangle, flags As TextFormatFlags, state As TextBoxState)

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.

    // Use DrawText with the current TextFormatFlags.

protected:
    virtual void OnPaint(PaintEventArgs^ e) override
    {
        __super::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";
        }
    }
// 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";
    }
}
' Use DrawText with the current TextFormatFlags.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)

    If TextBoxRenderer.IsSupported Then
        TextBoxRenderer.DrawTextBox(e.Graphics, textBorder, Me.Text, _
            Me.Font, textRectangle, textFlags, TextBoxState.Normal)
        Me.Parent.Text = "CustomTextBox Enabled"
    Else
        Me.Parent.Text = "CustomTextBox Disabled"
    End If
End Sub

Remarks

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

Applies to