TextBox クラス

Windows テキスト ボックス コントロールを表します。

この型のすべてのメンバの一覧については、TextBox メンバ を参照してください。

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.TextBoxBase
               System.Windows.Forms.TextBox
                  System.Windows.Forms.DataGridTextBox

Public Class TextBox
   Inherits TextBoxBase
[C#]
public class TextBox : TextBoxBase
[C++]
public __gc class TextBox : public TextBoxBase
[JScript]
public class TextBox extends TextBoxBase

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

TextBox コントロールを使用すると、ユーザーはアプリケーションにテキストを入力できます。このコントロールには、複数行の編集やパスワード文字のマスクなど、標準の Windows テキスト ボックス コントロールにはない追加機能があります。

通常、 TextBox コントロールは、単一行のテキストを表示したり、入力として受け入れたりするために使用されます。 Multiline プロパティと ScrollBars プロパティを使用すると、複数行のテキストを表示または入力できます。 AcceptsTab プロパティと AcceptsReturn プロパティを true に設定して、複数行 TextBox コントロールでより多くのテキストを処理できるようにします。

MaxLength プロパティを特定の文字数に設定すると、 TextBox コントロールへ入力するテキストの文字数を制限できます。 TextBox コントロールは、パスワードやその他の機密情報を受け入れるためにも使用できます。 PasswordChar プロパティを使用すると、単一行形式のコントロールで入力した文字をマスクできます。

TextBox コントロールに入力するテキストを制限するには、コントロールに入力した各文字の妥当性を検査するために KeyDown イベントのイベント ハンドラを作成します。 ReadOnly プロパティを true に設定すると、 TextBox コントロールでデータが入力されないようにすることもできます。

メモ    TextBox コントロールのほとんどの機能は、 TextBoxBase クラスから継承します。

.NET Compact Framework - Windows CE .NET プラットフォームに関する注意点: Pocket PC アプリケーションの場合、単一行 TextBox ではタブ文字は角かっことして表示されます。ただし、 Multilinetrue に設定されている場合は通常どおりに表示されます。

使用例

垂直スクロール バーのある複数行 TextBox コントロールを作成する例を次に示します。この例では、 AcceptsTabAcceptsReturnWordWrap の各プロパティを使用して、テキスト ドキュメントを作成しやすいように複数行テキスト ボックス コントロールを設定します。

 
Private 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 to be entered 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!"
End Sub


[C#] 
private 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 to be entered 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!";
 }
 

[C++] 
private:
    void CreateMyMultilineTextBox() {
        // Create an instance of a TextBox control
        TextBox __gc *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 to be entered 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 = S"Welcome!";
    };


[JScript] 
private function CreateMyMultilineTextBox()
 {
    // Create an instance of a TextBox control
    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 to be entered 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!";
 }
 

必要条件

名前空間: System.Windows.Forms

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

TextBox メンバ | System.Windows.Forms 名前空間 | TextBoxBase