TextBox クラスとは? わかりやすく解説

TextBox クラス

ユーザーテキスト入力できるテキストベースコントロールです。

名前空間: System.Web.UI.MobileControls
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)
構文構文

<ValidationPropertyAttribute("Text")> _
Public Class TextBox
    Inherits TextControl
    Implements IPostBackDataHandler
[ValidationPropertyAttribute("Text")] 
public class TextBox : TextControl, IPostBackDataHandler
[ValidationPropertyAttribute(L"Text")] 
public ref class TextBox : public
 TextControl, IPostBackDataHandler
/** @attribute ValidationPropertyAttribute("Text") */ 
public class TextBox extends TextControl implements
 IPostBackDataHandler
ValidationPropertyAttribute("Text") 
public class TextBox extends
 TextControl implements IPostBackDataHandler
解説解説
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.MobileControls.MobileControl
       System.Web.UI.MobileControls.TextControl
        System.Web.UI.MobileControls.TextBox
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TextBox クラス

ユーザー入力用のテキスト ボックス コントロール表示します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<ValidationPropertyAttribute("Text")> _
<ControlValuePropertyAttribute("Text")> _
Public Class TextBox
    Inherits WebControl
    Implements IPostBackDataHandler, IEditableTextControl, ITextControl
[ValidationPropertyAttribute("Text")] 
[ControlValuePropertyAttribute("Text")] 
public class TextBox : WebControl, IPostBackDataHandler,
 IEditableTextControl, ITextControl
[ValidationPropertyAttribute(L"Text")] 
[ControlValuePropertyAttribute(L"Text")] 
public ref class TextBox : public
 WebControl, IPostBackDataHandler, IEditableTextControl, ITextControl
/** @attribute ValidationPropertyAttribute("Text") */ 
/** @attribute ControlValuePropertyAttribute("Text") */ 
public class TextBox extends WebControl implements
 IPostBackDataHandler, IEditableTextControl, 
    ITextControl
ValidationPropertyAttribute("Text") 
ControlValuePropertyAttribute("Text") 
public class TextBox extends
 WebControl implements IPostBackDataHandler, IEditableTextControl, 
    ITextControl
解説解説

TextBox サーバー コントロールは、ユーザーによるテキスト入力受け付け入力コントロールです。このコントロールの TextMode プロパティは、既定では TextBoxMode.SingleLine設定されており、単一テキスト ボックス表示されます。ただし、TextBox コントロール使用しTextMode プロパティの値を変更することで、複数テキスト ボックスや、ユーザー入力マスクするテキスト ボックス表示することもできます複数テキスト ボックス表示する場合は、このプロパティの値を TextBoxMode.MultiLine変更しますユーザー入力マスクするテキスト ボックス表示する場合は、TextBoxMode.Password変更しますTextBox コントロール表示されるテキストは、Text プロパティ使用して指定または確認します

TextBox コントロールには、コントロール外観制御するためのプロパティいくつか格納されています。テキスト ボックス表示幅 (文字数) は、Columns プロパティによって決まりますTextBox コントロール複数テキスト ボックス場合表示行数Rows プロパティによって決まりますTextBox コントロール内のテキスト折り返して表示するには、Wrap プロパティtrue設定します

また、TextBox コントロールへのデータ入力方法指定するときに設定するプロパティいくつかありますコントロール内のテキスト変更されないようにするには、ReadOnly プロパティtrue設定しますユーザー入力できる文字数指定して制限する必要がある場合は、MaxLength プロパティ設定します

TextBoxインスタンス初期プロパティ値の一覧については、TextBox コンストラクタトピック参照してください

注意に関するメモ注意

このコントロールは、ユーザー入力受け入れるために使用できますユーザー入力には悪意のあるクライアント スクリプト含まれている可能性ありますアプリケーション表示する前にクライアントから送信され実行スクリプトSQL ステートメントなどのコード情報はすべて検証してください入力テキストコントロール表示する前に検証コントロール使用してユーザー入力検証できますASP.NET には入力要求検証機能があり、ユーザー入力の中のスクリプトおよび HTMLブロックできます詳細については、「標準コントロールセキュリティ保護」、「方法 : HTML エンコーディング文字列適用して Web アプリケーションスクリプトによる攻略から保護する」、および「ASP.NET Web ページにおけるユーザー入力検証」を参照してください

ユーザー補助

TopicLocation
チュートリアル : Visual Web Developer での ASP.NET マスタ ページ作成使用Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : Visual Web Developer での基本的な Web ページ作成Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : Web フォーム ページにおけるユーザー入力検証Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : カスタム ビジネス オブジェクトへのデータ バインディングVisual Studio での ASP .NET Web アプリケーション作成
チュートリアル: Visual Web Developer でのカスケード スタイル シートスタイル操作Visual Studio での ASP .NET Web アプリケーション作成
方法 : ASP.NET Web サーバー コントロールフォーカス設定するASP .NET Web アプリケーション作成
方法 : ASP.NET Web サーバー コントロールプロパティ設定するASP .NET Web アプリケーション作成
方法 : HTML エンコーディング文字列適用して Web アプリケーションスクリプトによる攻略から保護するASP .NET Web アプリケーション作成
方法 : TextBox Web サーバー コントロールでの変更応答するASP .NET Web アプリケーション作成
方法 : TextBox Web サーバー コントロール複数行入力を指定するASP .NET Web アプリケーション作成
方法 : TextBox Web サーバー コントロールの値を取得および設定するASP .NET Web アプリケーション作成
方法 : パスワード入力のための TextBox Web サーバー コントロール設定するASP .NET Web アプリケーション作成
使用例使用例

TextBox コントロール使用してユーザー入力取得する方法次のコード例示しますユーザーが [Add] ボタンクリックすると、テキスト ボックス入力された値の合計表示されます。

<%@ Page Language="VB" AutoEventWireup="True"
 %>

<html> 

<head>

   <script runat="server">

      Protected Sub AddButton_Click(sender
 As Object, e As EventArgs)

         Dim Answer As Integer

         Answer = Convert.ToInt32(Value1.Text) + Convert.ToInt32(Value2.Text)

         AnswerMessage.Text = Answer.ToString()

      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> TextBox Example </h3>

      <table>

         <tr>

            <td colspan="5">

               Enter integer values into the text boxes. <br>
               Click the Add button to add the two values. <br>
               Click the Reset button to reset the text boxes.

            </td>

         </tr>

         <tr>

            <td colspan="5">

               &nbsp;

            </td>

         </tr>

         <tr align="center">

            <td>

               <asp:TextBox ID="Value1"
                    Columns="2"
                    MaxLength="3"
                    Text="1"
                    runat="server"/>

            </td>

            <td>

               + 

            </td>

            <td>

               <asp:TextBox ID="Value2"
                    Columns="2"
                    MaxLength="3"
                    Text="1"
                    runat="server"/>

            </td>

            <td>

               =

            </td>

            <td>
               
               <asp:Label ID="AnswerMessage"
                    runat="server"/>

            </td>

         </tr>

         <tr>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value1RequiredValidator"
                    ControlToValidate="Value1"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:RangeValidator
                    ID="Value1RangeValidator"
                    ControlToValidate="Value1"
                    Type="Integer"
                    MinimumValue="1"
                    MaximumValue="100"
                    ErrorMessage="Please enter an integer <br>
 between than 1 and 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value2RequiredValidator"
                    ControlToValidate="Value2"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:RangeValidator
                    ID="Value2RangeValidator"
                    ControlToValidate="Value2"
                    Type="Integer"
                    MinimumValue="1"
                    MaximumValue="100"
                    ErrorMessage="Please enter an integer <br>
 between than 1 and 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td>

               &nbsp
 
            </td

         </tr>

         <tr align="center">

            <td colspan="4">

               <asp:Button ID="AddButton"
                    Text="Add"
                    OnClick="AddButton_Click"
                    runat="server"/>

            </td>

            <td>

               &nbsp;

            </td>

         </tr>

      </table>

   </form>

</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      protected void AddButton_Click(Object
 sender, EventArgs e)
      {
         int Answer;

         Answer = Convert.ToInt32(Value1.Text) + Convert.ToInt32(Value2.Text);

         AnswerMessage.Text = Answer.ToString();

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> TextBox Example </h3>

      <table>

         <tr>

            <td colspan="5">

               Enter integer values into the text boxes. <br>
               Click the Add button to add the two values. <br>
               Click the Reset button to reset the text boxes.

            </td>

         </tr>

         <tr>

            <td colspan="5">

               &nbsp;

            </td>

         </tr>

         <tr align="center">

            <td>

               <asp:TextBox ID="Value1"
                    Columns="2"
                    MaxLength="3"
                    Text="1"
                    runat="server"/>

            </td>

            <td>

               + 

            </td>

            <td>

               <asp:TextBox ID="Value2"
                    Columns="2"
                    MaxLength="3"
                    Text="1"
                    runat="server"/>

            </td>

            <td>

               =

            </td>

            <td>
               
               <asp:Label ID="AnswerMessage"
                    runat="server"/>

            </td>

         </tr>

         <tr>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value1RequiredValidator"
                    ControlToValidate="Value1"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:RangeValidator
                    ID="Value1RangeValidator"
                    ControlToValidate="Value1"
                    Type="Integer"
                    MinimumValue="1"
                    MaximumValue="100"
                    ErrorMessage="Please enter an integer <br> between
 than 1 and 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value2RequiredValidator"
                    ControlToValidate="Value2"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:RangeValidator
                    ID="Value2RangeValidator"
                    ControlToValidate="Value2"
                    Type="Integer"
                    MinimumValue="1"
                    MaximumValue="100"
                    ErrorMessage="Please enter an integer <br> between
 than 1 and 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td>

               &nbsp
 
            </td

         </tr>

         <tr align="center">

            <td colspan="4">

               <asp:Button ID="AddButton"
                    Text="Add"
                    OnClick="AddButton_Click"
                    runat="server"/>

            </td>

            <td>

               &nbsp;

            </td>

         </tr>

      </table>

   </form>

</body>
</html>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.TextBox
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TextBox クラス

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

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class TextBox
    Inherits TextBoxBase
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class TextBox : TextBoxBase
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class TextBox : public
 TextBoxBase
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class TextBox extends TextBoxBase
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class TextBox extends
 TextBoxBase
解説解説

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

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

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

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

メモメモ

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

Windows Mobile for Pocket PCWindows Mobile for SmartphoneWindows CE プラットフォームメモ : Pocket PC アプリケーション場合単一テキスト ボックスではタブ文字角かっこ ([]) として表示されます。ただし、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

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!";
 }
 
private:
   void CreateMyMultilineTextBox()
   {
      // Create an instance of a TextBox control
      TextBox^ textBox1 = gcnew 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!";
   }
private void CreateMyMultilineTextBox()
{
    // Create an instance of a TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the Multiline property to true.
    textBox1.set_Multiline(true);
    // Add vertical scroll bars to the TextBox control.
    textBox1.set_ScrollBars(ScrollBars.Vertical);
    // Allow the RETURN key to be entered in the TextBox control.
    textBox1.set_AcceptsReturn(true);
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.set_AcceptsTab(true);
    // Set WordWrap to True to allow text to wrap to the next line.
    textBox1.set_WordWrap(true);
    // Set the default text of the control.
    textBox1.set_Text("Welcome!");
} //CreateMyMultilineTextBox
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.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.TextBoxBase
          System.Windows.Forms.TextBox
             System.Windows.Forms.DataGridTextBox
             System.Windows.Forms.DataGridViewTextBoxEditingControl
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からTextBox クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTextBox クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTextBox クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TextBox クラス」の関連用語

TextBox クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TextBox クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS