TextBox.ScrollBars 属性

定义

获取或设置哪些滚动条应出现在多行 TextBox 控件中。

C#
public System.Windows.Forms.ScrollBars ScrollBars { get; set; }

属性值

ScrollBars 枚举值之一,它指示多行 TextBox 控件显示时是不带滚动条、带有水平滚动条、带有垂直滚动条还是同时带有这两种滚动条。 默认值为 ScrollBars.None

例外

分配给该属性的值不在该枚举的有效值范围内。

示例

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

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 TAB key to be entered 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!";
 }

注解

如果将 WordWrap 属性设置为 true,则不会显示水平滚动条,而不考虑属性 ScrollBars 的值。

适用于

产品 版本
.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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅