ComboBoxRenderer.DrawTextBox ComboBoxRenderer.DrawTextBox ComboBoxRenderer.DrawTextBox ComboBoxRenderer.DrawTextBox Method

定义

使用操作系统当前视觉样式绘制一个文本框。Draws a text box with the current visual style of the operating system.

重载

DrawTextBox(Graphics, Rectangle, ComboBoxState) DrawTextBox(Graphics, Rectangle, ComboBoxState) DrawTextBox(Graphics, Rectangle, ComboBoxState) DrawTextBox(Graphics, Rectangle, ComboBoxState)

在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds.

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

使用指定文本在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text.

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

使用指定的文本和文本边界在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text and text bounds.

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

使用指定的文本和文本格式在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text and text formatting.

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

使用指定的文本、文本格式和文本边界在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text, text formatting, and text bounds.

DrawTextBox(Graphics, Rectangle, ComboBoxState) DrawTextBox(Graphics, Rectangle, ComboBoxState) DrawTextBox(Graphics, Rectangle, ComboBoxState) DrawTextBox(Graphics, Rectangle, ComboBoxState)

在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds.

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

用于绘制文本框的 GraphicsThe Graphics used to draw the text box.

bounds
Rectangle Rectangle Rectangle Rectangle

指定文本框边界的 RectangleThe Rectangle that specifies the bounds of the text box.

state
ComboBoxState ComboBoxState ComboBoxState ComboBoxState

ComboBoxState 值之一,它指定文本框的可视状态。One of the ComboBoxState values that specifies the visual state of the text box.

异常

操作系统不支持视觉样式。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.

注解

在调用此方法之前, 应验证IsSupported属性是否返回。 trueBefore calling this method, you should verify that the IsSupported property returns true.

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

使用指定文本在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text.

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);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.VisualStyles.ComboBoxState -> unit

参数

g
Graphics Graphics Graphics Graphics

用于绘制文本框的 GraphicsThe Graphics used to draw the text box.

bounds
Rectangle Rectangle Rectangle Rectangle

指定文本框边界的 RectangleThe Rectangle that specifies the bounds of the text box.

comboBoxText
String String String String

要在文本框中绘制的 StringThe String to draw in the text box.

font
Font Font Font Font

要应用于 comboBoxTextFontThe Font to apply to comboBoxText.

state
ComboBoxState ComboBoxState ComboBoxState ComboBoxState

ComboBoxState 值之一,它指定文本框的可视状态。One of the ComboBoxState values that specifies the visual state of the text box.

异常

操作系统不支持视觉样式。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.

注解

在调用此方法之前, 应验证IsSupported属性是否返回。 trueBefore calling this method, you should verify that the IsSupported property returns true.

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

使用指定的文本和文本边界在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text and text bounds.

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);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.ComboBoxState -> unit

参数

g
Graphics Graphics Graphics Graphics

用于绘制文本框的 GraphicsThe Graphics used to draw the text box.

bounds
Rectangle Rectangle Rectangle Rectangle

指定文本框边界的 RectangleThe Rectangle that specifies the bounds of the text box.

comboBoxText
String String String String

要在文本框中绘制的 StringThe String to draw in the text box.

font
Font Font Font Font

要应用于 comboBoxTextFontThe Font to apply to comboBoxText.

textBounds
Rectangle Rectangle Rectangle Rectangle

Rectangle,指定 comboBoxText 的绘制边界。The Rectangle that specifies the bounds in which to draw comboBoxText.

state
ComboBoxState ComboBoxState ComboBoxState ComboBoxState

ComboBoxState 值之一,它指定文本框的可视状态。One of the ComboBoxState values that specifies the visual state of the text box.

异常

操作系统不支持视觉样式。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.

示例

下面的代码示例使用自DrawTextBox(Graphics, Rectangle, String, Font, ComboBoxState)定义控件的OnPaint方法中的方法绘制一个文本框。The following code example uses the DrawTextBox(Graphics, Rectangle, String, Font, ComboBoxState) method in a custom control's OnPaint method to draw a text box. 此代码示例是为ComboBoxRenderer类提供的更大示例的一部分。This code example is part of a larger example provided for the ComboBoxRenderer class.

      // 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属性是否返回。 trueBefore calling this method, you should verify that the IsSupported property returns true.

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

使用指定的文本和文本格式在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text and text formatting.

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);
static member DrawTextBox : System.Drawing.Graphics * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.TextFormatFlags * System.Windows.Forms.VisualStyles.ComboBoxState -> unit

参数

g
Graphics Graphics Graphics Graphics

用于绘制文本框的 GraphicsThe Graphics used to draw the text box.

bounds
Rectangle Rectangle Rectangle Rectangle

指定文本框边界的 RectangleThe Rectangle that specifies the bounds of the text box.

comboBoxText
String String String String

要在文本框中绘制的 StringThe String to draw in the text box.

font
Font Font Font Font

要应用于 comboBoxTextFontThe Font to apply to comboBoxText.

flags
TextFormatFlags TextFormatFlags TextFormatFlags TextFormatFlags

TextFormatFlags 值的按位组合。A bitwise combination of the TextFormatFlags values.

state
ComboBoxState ComboBoxState ComboBoxState ComboBoxState

ComboBoxState 值之一,它指定文本框的可视状态。One of the ComboBoxState values that specifies the visual state of the text box.

异常

操作系统不支持视觉样式。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.

注解

在调用此方法之前, 应验证IsSupported属性是否返回。 trueBefore calling this method, you should verify that the IsSupported property returns true.

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

使用指定的文本、文本格式和文本边界在指定边界内绘制指定状态的文本框。Draws a text box in the specified state and bounds, with the specified text, text formatting, and text bounds.

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);
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

参数

g
Graphics Graphics Graphics Graphics

用于绘制文本框的 GraphicsThe Graphics used to draw the text box.

bounds
Rectangle Rectangle Rectangle Rectangle

指定文本框边界的 RectangleThe Rectangle that specifies the bounds of the text box.

comboBoxText
String String String String

要在文本框中绘制的 StringThe String to draw in the text box.

font
Font Font Font Font

要应用于 comboBoxTextFontThe Font to apply to comboBoxText.

textBounds
Rectangle Rectangle Rectangle Rectangle

Rectangle,指定 comboBoxText 的绘制边界。The Rectangle that specifies the bounds in which to draw comboBoxText.

flags
TextFormatFlags TextFormatFlags TextFormatFlags TextFormatFlags

TextFormatFlags 值的按位组合。A bitwise combination of the TextFormatFlags values.

state
ComboBoxState ComboBoxState ComboBoxState ComboBoxState

ComboBoxState 值之一,它指定文本框的可视状态。One of the ComboBoxState values that specifies the visual state of the text box.

异常

操作系统不支持视觉样式。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.

注解

在调用此方法之前, 应验证IsSupported属性是否返回。 trueBefore calling this method, you should verify that the IsSupported property returns true.

适用于