다음을 통해 공유


TextBox Control Overview (Windows Forms)

Windows Forms text boxes are used to get input from the user or to display text. The TextBox control is generally used for editable text, although it can also be made read-only. Text boxes can display multiple lines, wrap text to the size of the control, and add basic formatting. The TextBox control provides a single format style for text displayed or entered into the control. To display multiple types of formatted text, use the RichTextBox control. For more information, see RichTextBox Control Overview (Windows Forms).

Working with the TextBox Control

The text displayed by the control is contained in the Text property. By default, you can enter up to 2048 characters in a text box. If you set the Multiline property to true, you can enter up to 32 KB of text. The Text property can be set at design time with the Properties Window, at run time in code, or by user input at run time. The current contents of a text box can be retrieved at run time by reading the Text property.

The following code example sets text in the control at run time. TheInitializeMyControlprocedure will not execute automatically; it must be called.

Private Sub InitializeMyControl()
   ' Put some text into the control first.
   TextBox1.Text = "This is a TextBox control."
End Sub
private void InitializeMyControl() {
   // Put some text into the control first.
   textBox1.Text = "This is a TextBox control.";
}
private void InitializeMyControl() 
{
   // Put some text into the control first.
   textBox1.set_Text("This is a TextBox control.");
}
private:
   void InitializeMyControl()
   {
      // Put some text into the control first.
      textBox1->Text = "This is a TextBox control.";
   }

See Also

Tasks

How to: Control the Insertion Point in a Windows Forms TextBox Control
How to: Create a Password Text Box with the Windows Forms TextBox Control
How to: Create a Read-Only Text Box (Windows Forms)
How to: Put Quotation Marks in a String (Windows Forms)
How to: Select Text in the Windows Forms TextBox Control
How to: View Multiple Lines in the Windows Forms TextBox Control

Reference

TextBox

Other Resources

TextBox Control (Windows Forms)