TextBoxBase 类
实现文本控件要求的基本功能。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public MustInherit Class TextBoxBase
Inherits Control
用法
Dim instance As TextBoxBase
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public abstract class TextBoxBase : Control
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
public ref class TextBoxBase abstract : public Control
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute ComVisibleAttribute(true) */
public abstract class TextBoxBase extends Control
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
ComVisibleAttribute(true)
public abstract class TextBoxBase extends Control
备注
此类实现文本操作控件(如 TextBox 和 RichTextBox)的核心功能。这些功能包括文本选择、“剪贴板”功能、多行文本控件支持和多种事件。
给继承者的说明 通常不从 TextBoxBase 继承。若要创建自己的文本控件类,可从 TextBox 或 RichTextBox 继承。
示例
下面的代码示例使用派生类 TextBox 来创建一个带垂直滚动条的多行 TextBox 控件。此示例还使用 AcceptsTab、AcceptsReturn 和 WordWrap 属性来使多行文本框控件可用于创建文本文档。
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
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:
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.set_Multiline(true);
// Add vertical scroll bars to the TextBox control.
textBox1.set_ScrollBars(ScrollBars.Vertical);
// Allow the RETURN key in the TextBox control.
textBox1.set_AcceptsReturn(true);
// Allow the TAB key to be entered in the TextBox control.
textBox1.set_AcceptsTab(true);
// Set WordWrap to true to allow text to wrap to the next line.
textBox1.set_WordWrap(true);
// Set the default text of the control.
textBox1.set_Text("Welcome!" + Environment.get_NewLine()
+ "Second Line");
} //CreateMyMultilineTextBox
继承层次结构
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.TextBoxBase
System.Windows.Forms.MaskedTextBox
System.Windows.Forms.RichTextBox
System.Windows.Forms.TextBox
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
TextBoxBase 成员
System.Windows.Forms 命名空间
TextBox 类
RichTextBox 类