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

適用於