通过


ComboBoxRenderer.DrawTextBox 方法

定义

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

重载

名称 说明
DrawTextBox(Graphics, Rectangle, ComboBoxState)

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

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

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

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

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

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

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

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

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

DrawTextBox(Graphics, Rectangle, ComboBoxState)

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

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

参数

g
Graphics

Graphics用于绘制文本框的文本框。

bounds
Rectangle

指定 Rectangle 文本框的边界。

state
ComboBoxState

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

例外

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

-或-

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

-或-

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

注解

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

适用于

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

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

参数

g
Graphics

Graphics用于绘制文本框的文本框。

bounds
Rectangle

指定 Rectangle 文本框的边界。

comboBoxText
String

String 绘制的文本框。

font
Font

Font要应用于comboBoxText的 。

state
ComboBoxState

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

例外

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

-或-

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

-或-

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

注解

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

适用于

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

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

参数

g
Graphics

Graphics用于绘制文本框的文本框。

bounds
Rectangle

指定 Rectangle 文本框的边界。

comboBoxText
String

String 绘制的文本框。

font
Font

Font要应用于comboBoxText的 。

textBounds
Rectangle

指定要 Rectangle 在其中绘制 comboBoxText的边界的边界。

state
ComboBoxState

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

例外

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

-或-

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

-或-

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

示例

下面的代码示例使用 DrawTextBox(Graphics, Rectangle, String, Font, ComboBoxState) 自定义控件 OnPaint 方法中的方法绘制文本框。 该代码示例是 ComboBoxRenderer 类中的一个较大示例的一部分。

      // Draw the combo box in the current state.
protected:
    virtual void OnPaint(PaintEventArgs^ e) override 
    {
        Control::OnPaint(e);

        if (!ComboBoxRenderer::IsSupported)
        {
            this->Parent->Text = "Visual Styles Disabled";
            return;
        }

        this->Parent->Text = "CustomComboBox Enabled";

        // Always draw the main text box and drop down arrow in their
        // current states
        ComboBoxRenderer::DrawTextBox(e->Graphics, topTextBoxRectangle,
            this->Text, this->Font, textBoxState);
        ComboBoxRenderer::DrawDropDownButton(e->Graphics, arrowRectangle,
            arrowState);

        // Only draw the bottom text box if the arrow has been clicked
        if (isActivated)
        {
            ComboBoxRenderer::DrawTextBox(e->Graphics,
                bottomTextBoxRectangle, bottomText, this->Font,
                textBoxState);
        }
    }

protected:
    virtual void OnMouseDown(MouseEventArgs^ e) override 
    {
        Control::OnMouseDown(e);

        // Check whether the user clicked the arrow.
        if (arrowRectangle.Contains(e->Location) &&
            ComboBoxRenderer::IsSupported)
        {
            // Draw the arrow in the pressed state.
            arrowState = ComboBoxState::Pressed;

            // The user has activated the combo box.
            if (!isActivated)
            {
                this->Text = "Clicked!";
                textBoxState = ComboBoxState::Pressed;
                isActivated = true;
            }

            // The user has deactivated the combo box.
            else
            {
                this->Text = "Click here";
                textBoxState = ComboBoxState::Normal;
                isActivated = false;
            }

            // Redraw the control.
            Invalidate();
        }
    }
// Draw the combo box in the current state.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    if (!ComboBoxRenderer.IsSupported)
    {
        this.Parent.Text = "Visual Styles Disabled";
        return;
    }

    this.Parent.Text = "CustomComboBox Enabled";

    // Always draw the main text box and drop down arrow in their 
    // current states
    ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle,
        this.Text, this.Font, textBoxState);
    ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle,
        arrowState);

    // Only draw the bottom text box if the arrow has been clicked
    if (isActivated)
    {
        ComboBoxRenderer.DrawTextBox(e.Graphics,
            bottomTextBoxRectangle, bottomText, this.Font,
            textBoxState);
    }
}

protected override void OnMouseDown(MouseEventArgs e)
{
    base.OnMouseDown(e);

    // Check whether the user clicked the arrow.
    if (arrowRectangle.Contains(e.Location) &&
        ComboBoxRenderer.IsSupported)
    {
        // Draw the arrow in the pressed state.
        arrowState = ComboBoxState.Pressed;

        // The user has activated the combo box.
        if (!isActivated)
        {
            this.Text = "Clicked!";
            textBoxState = ComboBoxState.Pressed;
            isActivated = true;
        }

        // The user has deactivated the combo box.
        else
        {
            this.Text = "Click here";
            textBoxState = ComboBoxState.Normal;
            isActivated = false;
        }

        // Redraw the control.
        Invalidate();
    }
}
' Draw the combo box in the current state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)

    If Not ComboBoxRenderer.IsSupported Then
        Me.Parent.Text = "Visual Styles	Disabled"
        Return
    End If

    Me.Parent.Text = "CustomComboBox Enabled"

    ' Always draw the main text box and drop down arrow in their 
    ' current states.
    ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle, _
        Me.Text, Me.Font, textBoxState)
    ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle, _
        arrowState)

    ' Only draw the bottom text box if the arrow has been clicked.
    If isActivated Then
        ComboBoxRenderer.DrawTextBox(e.Graphics, _
            bottomTextBoxRectangle, bottomText, Me.Font, textBoxState)
    End If
End Sub

Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
    MyBase.OnMouseDown(e)

    ' Check whether the user clicked the arrow.
    If arrowRectangle.Contains(e.Location) And _
        ComboBoxRenderer.IsSupported Then

        ' Draw the arrow in the pressed state.
        arrowState = ComboBoxState.Pressed

        ' The user has activated the combo box.
        If Not isActivated Then
            Me.Text = "Clicked!"
            textBoxState = ComboBoxState.Pressed
            isActivated = True

        ' The user has deactivated the combo box.
        Else
            Me.Text = "Click here"
            textBoxState = ComboBoxState.Normal
            isActivated = False
        End If

        ' Redraw the control.
        Invalidate()
    End If
End Sub

注解

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

适用于

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

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

参数

g
Graphics

Graphics用于绘制文本框的文本框。

bounds
Rectangle

指定 Rectangle 文本框的边界。

comboBoxText
String

String 绘制的文本框。

font
Font

Font要应用于comboBoxText的 。

flags
TextFormatFlags

值的按位组合 TextFormatFlags

state
ComboBoxState

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

例外

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

-或-

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

-或-

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

注解

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

适用于

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

Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs
Source:
ComboBoxRenderer.cs

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

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

参数

g
Graphics

Graphics用于绘制文本框的文本框。

bounds
Rectangle

指定 Rectangle 文本框的边界。

comboBoxText
String

String 绘制的文本框。

font
Font

Font要应用于comboBoxText的 。

textBounds
Rectangle

指定要 Rectangle 在其中绘制 comboBoxText的边界的边界。

flags
TextFormatFlags

值的按位组合 TextFormatFlags

state
ComboBoxState

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

例外

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

-或-

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

-或-

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

注解

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

适用于