通过


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)

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

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

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)

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

使用指定的文本绘制处于指定状态和边界的文本框控件。

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

Font要应用于textBoxText的 。

state
TextBoxState

TextBoxState指定文本框视觉状态的值之一。

例外

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

-或-

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

-或-

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

注解

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

适用于

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

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

使用指定的文本和文本边界绘制一个处于指定状态和边界的文本框控件。

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

Font要应用于textBoxText的 。

textBounds
Rectangle

指定 Rectangle . 的边界的textBoxText

state
TextBoxState

TextBoxState指定文本框视觉状态的值之一。

例外

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

-或-

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

-或-

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

注解

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

适用于

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

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

使用指定的文本和文本格式绘制处于指定状态和边界的文本框控件。

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

Font要应用于textBoxText的 。

flags
TextFormatFlags

值的按位组合 TextFormatFlags

state
TextBoxState

TextBoxState指定文本框视觉状态的值之一。

例外

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

-或-

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

-或-

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

注解

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

适用于

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

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

使用指定的文本、文本边界和文本格式绘制处于指定状态和边界的文本框控件。

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

Font要应用于textBoxText的 。

textBounds
Rectangle

指定 Rectangle . 的边界的textBoxText

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返回。

适用于