TextBoxRenderer.DrawTextBox 方法

定义

绘制具有操作系统的当前视觉样式的文本框控件。

重载

DrawTextBox(Graphics, Rectangle, TextBoxState)

绘制具有指定状态和边界的文本框控件。

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

绘制具有指定的状态和边界以及指定的文本的文本框控件。

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

绘制具有指定的状态和边界以及指定的文本和文本边界的文本框控件。

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

绘制具有指定的状态和边界以及指定的文本和文本格式的文本框控件。

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

绘制具有指定的状态和边界以及指定的文本、文本边界和文本格式的文本框控件。

DrawTextBox(Graphics, Rectangle, TextBoxState)

绘制具有指定状态和边界的文本框控件。

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)

参数

g
Graphics

用于绘制文本框的 Graphics

bounds
Rectangle

指定文本框边界的 Rectangle

state
TextBoxState

TextBoxState 值之一,它指定文本框的可视状态。

例外

操作系统不支持视觉样式。

- 或 -

用户在操作系统中禁用视觉样式。

- 或 -

视觉样式不应用于应用程序窗口的工作区。

注解

在调用此方法之前,应验证 属性是否 IsSupported 返回 true

适用于

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

绘制具有指定的状态和边界以及指定的文本的文本框控件。

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)

参数

g
Graphics

用于绘制文本框的 Graphics

bounds
Rectangle

指定文本框边界的 Rectangle

textBoxText
String

要在文本框中绘制的 String

font
Font

要应用于 textBoxTextFont

state
TextBoxState

TextBoxState 值之一,它指定文本框的可视状态。

例外

操作系统不支持视觉样式。

- 或 -

用户在操作系统中禁用视觉样式。

- 或 -

视觉样式不应用于应用程序窗口的工作区。

注解

在调用此方法之前,应验证 属性是否 IsSupported 返回 true

适用于

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

绘制具有指定的状态和边界以及指定的文本和文本边界的文本框控件。

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)

参数

g
Graphics

用于绘制文本框的 Graphics

bounds
Rectangle

指定文本框边界的 Rectangle

textBoxText
String

要在文本框中绘制的 String

font
Font

要应用于 textBoxTextFont

textBounds
Rectangle

指定 textBoxText 边界的 Rectangle

state
TextBoxState

TextBoxState 值之一,它指定文本框的可视状态。

例外

操作系统不支持视觉样式。

- 或 -

用户在操作系统中禁用视觉样式。

- 或 -

视觉样式不应用于应用程序窗口的工作区。

注解

在调用此方法之前,应验证 属性是否 IsSupported 返回 true

适用于

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

绘制具有指定的状态和边界以及指定的文本和文本格式的文本框控件。

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)

参数

g
Graphics

用于绘制文本框的 Graphics

bounds
Rectangle

指定文本框边界的 Rectangle

textBoxText
String

要在文本框中绘制的 String

font
Font

要应用于 textBoxTextFont

flags
TextFormatFlags

TextFormatFlags 值的按位组合。

state
TextBoxState

TextBoxState 值之一,它指定文本框的可视状态。

例外

操作系统不支持视觉样式。

- 或 -

用户在操作系统中禁用视觉样式。

- 或 -

视觉样式不应用于应用程序窗口的工作区。

注解

在调用此方法之前,应验证 属性是否 IsSupported 返回 true

适用于

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

绘制具有指定的状态和边界以及指定的文本、文本边界和文本格式的文本框控件。

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)

参数

g
Graphics

用于绘制文本框的 Graphics

bounds
Rectangle

指定文本框边界的 Rectangle

textBoxText
String

要在文本框中绘制的 String

font
Font

要应用于 textBoxTextFont

textBounds
Rectangle

指定 textBoxText 边界的 Rectangle

flags
TextFormatFlags

TextFormatFlags 值的按位组合。

state
TextBoxState

TextBoxState 值之一,它指定文本框的可视状态。

例外

操作系统不支持视觉样式。

- 或 -

用户在操作系统中禁用视觉样式。

- 或 -

视觉样式不应用于应用程序窗口的工作区。

示例

下面的代码示例演示如何在自定义控件的 OnPaint 方法中使用 DrawTextBox(Graphics, Rectangle, String, Font, Rectangle, TextFormatFlags, TextBoxState) 方法来绘制文本框。 此代码示例是为 TextBoxRenderer 类提供的一个更大示例的一部分。

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

注解

在调用此方法之前,应验证 属性是否 IsSupported 返回 true

适用于