TextBoxBase.Multiline 属性

定义

获取或设置一个值,该值指示它是否为多行文本框控件。Gets or sets a value indicating whether this is a multiline text box control.

public:
 virtual property bool Multiline { bool get(); void set(bool value); };
public virtual bool Multiline { get; set; }
member this.Multiline : bool with get, set
Public Overridable Property Multiline As Boolean

属性值

如果该控件是多行文本框控件,则为 true;否则为 falsetrue if the control is a multiline text box control; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例使用派生类 TextBox创建具有垂直滚动条的多行 TextBox 控件。The following code example uses TextBox, a derived class, to create a multiline TextBox control with vertical scroll bars. 此示例还使用 AcceptsTabAcceptsReturnWordWrap 属性,使多行文本框控件对于创建文本文档很有用。This example also uses the AcceptsTab, AcceptsReturn, and WordWrap properties to make the multiline text box control useful for creating text documents.

public:
   void CreateMyMultilineTextBox()
   {
      // Create an instance of a TextBox control.
      TextBox^ textBox1 = gcnew 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";
   }
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";
 }
Public Sub CreateMyMultilineTextBox()
    ' Create an instance of a TextBox control.
    Dim textBox1 As 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"
End Sub

注解

使用多行文本框可以在控件中显示多行文本。A multiline text box allows you to display more than one line of text in the control. 如果 WordWrap 属性设置为 true,则在多行文本框中输入的文本将被包装到控件中的下一行。If the WordWrap property is set to true, text entered into the multiline text box is wrapped to the next line in the control. 如果将 WordWrap 属性设置为 false,则在多行文本框控件中输入的文本将显示在同一行上,直到输入换行符。If the WordWrap property is set to false, text entered into the multiline text box control will be displayed on the same line until a newline character is entered.

可以将以下字符用作换行符:The following can be used as newline characters:

  • Environment.NewLine

  • ControlChars.CrLfControlChars.CrLf

  • vbCrLf (仅 Visual Basic)vbCrLf (Visual Basic only)

您可以使用 "ScrollBars" 属性向文本框添加滚动条,以显示水平和/或垂直滚动条。You can add scroll bars to a text box using the ScrollBars property to display horizontal and/or vertical scroll bars. 这允许用户滚动浏览超出控件尺寸的文本。This allows the user to scroll through the text that extends beyond the dimensions of the control.

备注

由于 Multiline 属性的默认值为 false,因此 TextBox 的默认大小将与字体大小一致,即使调整了 TextBox大小也是如此。Because the default value of the Multiline property is false, the default size of a TextBox will be in accordance with the font size even if you resize the TextBox. 若要为 TextBox获取一致大小,请将其 Multiline 属性设置为 "true"。To get a consistent size for your TextBox, set its Multiline property to true.

备注

在日语操作系统上,如果 Multiline 属性设置为 true,则设置 PasswordChar 属性将显示密码的文本,从而危及系统安全。On Japanese operating systems, if the Multiline property is set to true, setting the PasswordChar property will display the text of the password, thus compromising system security. 因此,在日语操作系统上,如果设置 PasswordChar 属性,请将 Multiline 属性设置为 falseTherefore, on Japanese operating systems, set the Multiline property to false if you set the PasswordChar property.

备注

默认情况下,此属性设置为所有派生类 falseRichTextBox 控件除外。This property is set to false by default for all derived classes, with the exception of the RichTextBox control.

对于 RichTextBox 控件,RichTextBox.Multiline 属性会影响控件是否将自动调整大小,如下所示:For a RichTextBox control, the RichTextBox.Multiline property affects whether or not the control will automatically resize, as follows:

适用于

另请参阅