Control.Text 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置与此控件关联的文本。
public:
virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public virtual string Text { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Text : string with get, set
Public Overridable Property Text As String
属性值
与该控件关联的文本。
- 属性
示例
下面的代码示例创建并 GroupBox 设置其一些常见属性。 该示例在 TextBox 组框中创建并设置它 Location 。 接下来,它将组框的属性设置为 Text 组框,并将组框停靠在窗体顶部。 最后,它通过将属性false
设置为Enabled禁用组框来禁用组框,这将导致禁用组框中包含的所有控件。
// Add a GroupBox to a form and set some of its common properties.
private:
void AddMyGroupBox()
{
// Create a GroupBox and add a TextBox to it.
GroupBox^ groupBox1 = gcnew GroupBox;
TextBox^ textBox1 = gcnew TextBox;
textBox1->Location = Point(15,15);
groupBox1->Controls->Add( textBox1 );
// Set the Text and Dock properties of the GroupBox.
groupBox1->Text = "MyGroupBox";
groupBox1->Dock = DockStyle::Top;
// Disable the GroupBox (which disables all its child controls)
groupBox1->Enabled = false;
// Add the Groupbox to the form.
this->Controls->Add( groupBox1 );
}
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
// Create a GroupBox and add a TextBox to it.
GroupBox groupBox1 = new GroupBox();
TextBox textBox1 = new TextBox();
textBox1.Location = new Point(15, 15);
groupBox1.Controls.Add(textBox1);
// Set the Text and Dock properties of the GroupBox.
groupBox1.Text = "MyGroupBox";
groupBox1.Dock = DockStyle.Top;
// Disable the GroupBox (which disables all its child controls)
groupBox1.Enabled = false;
// Add the Groupbox to the form.
this.Controls.Add(groupBox1);
}
' Add a GroupBox to a form and set some of its common properties.
Private Sub AddMyGroupBox()
' Create a GroupBox and add a TextBox to it.
Dim groupBox1 As New GroupBox()
Dim textBox1 As New TextBox()
textBox1.Location = New Point(15, 15)
groupBox1.Controls.Add(textBox1)
' Set the Text and Dock properties of the GroupBox.
groupBox1.Text = "MyGroupBox"
groupBox1.Dock = DockStyle.Top
' Disable the GroupBox (which disables all its child controls)
groupBox1.Enabled = False
' Add the Groupbox to the form.
Me.Controls.Add(groupBox1)
End Sub
注解
控件 Text 的属性由每个派生类使用不同的属性。 例如, Text 属性显示在窗体顶部的 Form 标题栏中,字符计数相当小,通常显示应用程序或文档名称。 但是,属性RichTextBox可能很大,Text并且可以包含用于设置文本格式的众多非visual 字符。 例如,可以通过调整属性或添加空格或制表符来对齐Font文本来设置以格式显示RichTextBox的文本。
继承者说明
重写 Text 派生类中的属性时,请使用基类的属性 Text 扩展基实现。 否则,必须提供所有实现。 无需同时替代 get
属性和 set
访问器 Text ;仅在需要时可以替代一个。