Control.Text Egenskap

Definition

Hämtar eller anger den text som är associerad med den här kontrollen.

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

Egenskapsvärde

Texten som är associerad med den här kontrollen.

Attribut

Exempel

Följande kodexempel skapar en GroupBox och anger några av dess gemensamma egenskaper. Exemplet skapar en TextBox och anger dess Location i grupprutan. Därefter anger den Text egenskapen för grupprutan och dockar grupprutan överst i formuläret. Slutligen inaktiveras grupprutan genom att egenskapen anges Enabled till false, vilket gör att alla kontroller i grupprutan inaktiveras.

   // 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

Kommentarer

Kontrollens Text egenskap används på olika sätt av varje härledd klass. Egenskapen för en Text visas till exempel Form i namnlisten överst i formuläret, är ganska liten i antal tecken och visar vanligtvis program- eller dokumentnamnet. Egenskapen för en Text kan dock RichTextBox vara stor och kan innehålla många icke-visningstecken som används för att formatera texten. Texten som visas i en RichTextBox kan till exempel formateras genom att Font justera egenskaperna, eller genom att lägga till blanksteg eller tabbtecken för att justera texten.

Anteckningar till arvingar

När du åsidosättar Text egenskapen i en härledd klass använder du basklassens Text egenskap för att utöka basimplementeringen. Annars måste du ange all implementering. Du behöver inte åsidosätta både get egenskapens och set -åtkomsten Text . Du kan bara åsidosätta en om det behövs.

Gäller för

Se även