共用方式為


Control.Text 屬性

定義

取得或設定與此控制項相關的文字。

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 群組框的屬性,並將群組框停靠到表單的頂端。 最後,它會透過將屬性falseEnabled為 來停用群組框,這會使群組框內的所有控制項被停用。

   // 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 ,a Form 的屬性會顯示在表單頂端的標題欄,字元數相當少,通常會顯示應用程式或文件名稱。 然而, Text a RichTextBox 的屬性可以很大,且可能包含許多用於格式化文字的非視覺字元。 例如,顯示在 a RichTextBox 中的文字可以透過調整 Font 屬性,或加入空格或制表字元來對齊文字來進行格式化。

給繼承者的注意事項

在導出類別中覆寫該 Text 屬性時,請使用基底類別的 Text 特性來擴充基底實作。 否則,你必須提供所有的實作。 你不必同時覆寫get該財產的setText附屬裝置;如果需要,你只能覆蓋其中一項。

適用於

另請參閱