TextBoxBase.Text 属性

定义

获取或设置文本框中的当前文本。

C#
public override string Text { get; set; }

属性值

String

在控件中显示的文本。

示例

下面的代码示例使用 TextBox派生类创建具有垂直滚动条的多行 TextBox 控件。 此示例还使用AcceptsTabAcceptsReturnWordWrap属性使多行文本框控件可用于创建文本文档。

C#
public void CreateMyMultilineTextBox()
 {
    // Create an instance of a TextBox control.
    TextBox textBox1 = new TextBox();
    
    // Set the Multiline property to true.
    textBox1.Multiline = true;
    // Add vertical scroll bars to the TextBox control.
    textBox1.ScrollBars = ScrollBars.Vertical;
    // Allow the RETURN key in the TextBox control.
    textBox1.AcceptsReturn = true;
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.AcceptsTab = true;
    // Set WordWrap to true to allow text to wrap to the next line.
    textBox1.WordWrap = true;
    // Set the default text of the control.
    textBox1.Text = "Welcome!" + Environment.NewLine + "Second Line";
 }

注解

若要在文本框中显示多行文本,请将 Multiline 属性设置为 true。 若要读取或设置多行文本框的文本,请使用 Lines 该属性。 控件中 RichTextBox 可输入的文本量仅受可用系统内存的限制。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅