次の方法で共有


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 プロパティを設定し、グループ ボックスをフォームの上部にドッキングします。 最後に、 Enabled プロパティを false に設定することで、グループ ボックスを無効にします。これにより、グループ ボックスに含まれるすべてのコントロールが無効になります。

   // 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 プロパティは、派生クラスごとに異なる方法で使用されます。 たとえば、FormTextプロパティは、フォームの上部にあるタイトル バーに表示され、文字数が非常に小さく、通常はアプリケーションまたはドキュメント名が表示されます。 ただし、RichTextBoxTextプロパティは大きくすることができ、テキストの書式設定に使用される多数の非ビジュアル文字を含めることができます。 たとえば、 RichTextBox に表示されるテキストは、 Font プロパティを調整するか、スペースまたはタブ文字を追加してテキストを配置することで書式設定できます。

注意 (継承者)

派生クラスの Text プロパティをオーバーライドする場合は、基底クラスの Text プロパティを使用して基本実装を拡張します。 それ以外の場合は、すべての実装を指定する必要があります。 Text プロパティのgetアクセサーと set アクセサーの両方をオーバーライドする必要はありません。必要に応じて 1 つだけオーバーライドできます。

適用対象

こちらもご覧ください