TextBox.ScrollBars 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置哪些滚动条应出现在多行 TextBox 控件中。
public:
property System::Windows::Forms::ScrollBars ScrollBars { System::Windows::Forms::ScrollBars get(); void set(System::Windows::Forms::ScrollBars value); };
public System.Windows.Forms.ScrollBars ScrollBars { get; set; }
member this.ScrollBars : System.Windows.Forms.ScrollBars with get, set
Public Property ScrollBars As ScrollBars
属性值
ScrollBars 枚举值之一,它指示多行 TextBox 控件显示时是不带滚动条、带有水平滚动条、带有垂直滚动条还是同时带有这两种滚动条。 默认值为 ScrollBars.None
。
例外
分配给该属性的值不在该枚举的有效值范围内。
示例
下面的代码示例创建具有垂直滚动条的多行 TextBox 控件。 此示例还使用 AcceptsTab、 AcceptsReturn和 WordWrap 属性使多行 TextBox 控件可用于创建文本文档。
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 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!";
}
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!";
}
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 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!"
End Sub
注解
如果将 WordWrap 属性设置为 true
,则不会显示水平滚动条,而不考虑属性 ScrollBars 的值。