Share via


ComboBoxRenderer.DrawTextBox Methode

Definition

Zeichnet ein Textfeld mit dem aktuellen visuellen Stil des Betriebssystems.

Überlädt

DrawTextBox(Graphics, Rectangle, ComboBoxState)

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen.

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen mit dem angegebenen Text.

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen sowie mit dem angegebenen Text und den angegebenen Textbegrenzungen.

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen sowie mit dem angegebenen Text und der angegebenen Textformatierung.

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen sowie mit dem angegebenen Text, der angegebenen Textformatierung und den angegebenen Textbegrenzungen.

DrawTextBox(Graphics, Rectangle, ComboBoxState)

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen.

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)

Parameter

g
Graphics

Die zum Zeichnen des Textfelds verwendete Graphics-Klasse.

bounds
Rectangle

Das Rectangle, das die Begrenzungen des Textfelds angibt.

state
ComboBoxState

Einer der ComboBoxState-Werte, der den visuellen Zustand des Textfelds angibt.

Ausnahmen

Das Betriebssystem unterstützt keine visuellen Stile.

- oder -

Visuelle Stile wurden durch den Benutzer im Betriebssystem deaktiviert.

- oder -

Visuelle Stile werden nicht auf den Clientbereich der Anwendungsfenster angewendet.

Hinweise

Bevor Sie diese Methode aufrufen, sollten Sie überprüfen, ob die IsSupported Eigenschaft zurückgegeben wird true.

Gilt für

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen mit dem angegebenen 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);
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)

Parameter

g
Graphics

Die zum Zeichnen des Textfelds verwendete Graphics-Klasse.

bounds
Rectangle

Das Rectangle, das die Begrenzungen des Textfelds angibt.

comboBoxText
String

Die String, die im Textfeld gezeichnet werden soll.

font
Font

Der Font, der auf die comboBoxText angewendet werden soll.

state
ComboBoxState

Einer der ComboBoxState-Werte, der den visuellen Zustand des Textfelds angibt.

Ausnahmen

Das Betriebssystem unterstützt keine visuellen Stile.

- oder -

Visuelle Stile wurden durch den Benutzer im Betriebssystem deaktiviert.

- oder -

Visuelle Stile werden nicht auf den Clientbereich der Anwendungsfenster angewendet.

Hinweise

Bevor Sie diese Methode aufrufen, sollten Sie überprüfen, ob die IsSupported Eigenschaft zurückgegeben wird true.

Gilt für

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen sowie mit dem angegebenen Text und den angegebenen Textbegrenzungen.

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)

Parameter

g
Graphics

Die zum Zeichnen des Textfelds verwendete Graphics-Klasse.

bounds
Rectangle

Das Rectangle, das die Begrenzungen des Textfelds angibt.

comboBoxText
String

Die String, die im Textfeld gezeichnet werden soll.

font
Font

Der Font, der auf die comboBoxText angewendet werden soll.

textBounds
Rectangle

Das Rectangle, das die Begrenzungen angibt, innerhalb derer comboBoxText gezeichnet werden soll.

state
ComboBoxState

Einer der ComboBoxState-Werte, der den visuellen Zustand des Textfelds angibt.

Ausnahmen

Das Betriebssystem unterstützt keine visuellen Stile.

- oder -

Visuelle Stile wurden durch den Benutzer im Betriebssystem deaktiviert.

- oder -

Visuelle Stile werden nicht auf den Clientbereich der Anwendungsfenster angewendet.

Beispiele

Im folgenden Codebeispiel wird die DrawTextBox(Graphics, Rectangle, String, Font, ComboBoxState) Methode in der Methode eines benutzerdefinierten Steuerelements OnPaint verwendet, um ein Textfeld zu zeichnen. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die ComboBoxRenderer Klasse bereitgestellt wird.

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

Hinweise

Bevor Sie diese Methode aufrufen, sollten Sie überprüfen, ob die IsSupported Eigenschaft zurückgegeben wird true.

Gilt für

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen sowie mit dem angegebenen Text und der angegebenen Textformatierung.

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)

Parameter

g
Graphics

Die zum Zeichnen des Textfelds verwendete Graphics-Klasse.

bounds
Rectangle

Das Rectangle, das die Begrenzungen des Textfelds angibt.

comboBoxText
String

Die String, die im Textfeld gezeichnet werden soll.

font
Font

Der Font, der auf die comboBoxText angewendet werden soll.

flags
TextFormatFlags

Eine bitweise Kombination der TextFormatFlags-Werte.

state
ComboBoxState

Einer der ComboBoxState-Werte, der den visuellen Zustand des Textfelds angibt.

Ausnahmen

Das Betriebssystem unterstützt keine visuellen Stile.

- oder -

Visuelle Stile wurden durch den Benutzer im Betriebssystem deaktiviert.

- oder -

Visuelle Stile werden nicht auf den Clientbereich der Anwendungsfenster angewendet.

Hinweise

Bevor Sie diese Methode aufrufen, sollten Sie überprüfen, ob die IsSupported Eigenschaft zurückgegeben wird true.

Gilt für

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

Zeichnet ein Textfeld im angegebenen Zustand und innerhalb der angegebenen Begrenzungen sowie mit dem angegebenen Text, der angegebenen Textformatierung und den angegebenen Textbegrenzungen.

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)

Parameter

g
Graphics

Die zum Zeichnen des Textfelds verwendete Graphics-Klasse.

bounds
Rectangle

Das Rectangle, das die Begrenzungen des Textfelds angibt.

comboBoxText
String

Die String, die im Textfeld gezeichnet werden soll.

font
Font

Der Font, der auf die comboBoxText angewendet werden soll.

textBounds
Rectangle

Das Rectangle, das die Begrenzungen angibt, innerhalb derer comboBoxText gezeichnet werden soll.

flags
TextFormatFlags

Eine bitweise Kombination der TextFormatFlags-Werte.

state
ComboBoxState

Einer der ComboBoxState-Werte, der den visuellen Zustand des Textfelds angibt.

Ausnahmen

Das Betriebssystem unterstützt keine visuellen Stile.

- oder -

Visuelle Stile wurden durch den Benutzer im Betriebssystem deaktiviert.

- oder -

Visuelle Stile werden nicht auf den Clientbereich der Anwendungsfenster angewendet.

Hinweise

Bevor Sie diese Methode aufrufen, sollten Sie überprüfen, ob die IsSupported Eigenschaft zurückgegeben wird true.

Gilt für