TextBox クラス
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)

<ValidationPropertyAttribute("Text")> _ Public Class TextBox Inherits TextControl Implements IPostBackDataHandler
[ValidationPropertyAttribute(L"Text")] public ref class TextBox : public TextControl, IPostBackDataHandler

TextBox コントロールでは、単一行のテキストしか入力できません。このコントロールは、IPostBackDataHandler インターフェイスも実装しています。このインターフェイスは、入力を受け付け、ポストバックを生成できます。ただし、WML を使用するデバイスでは、入力したデータがサーバーにポストバックされないことがあります。ユーザーがテキスト ボックスに値を入力すると、TextControl 基本クラスから継承された Text プロパティに値が格納されます。


System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.TextControl
System.Web.UI.MobileControls.TextBox


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TextBox クラス
アセンブリ: 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

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 ページにおけるユーザー入力の検証」を参照してください。 |
ユーザー補助
このコントロールに既定でレンダリングされるマークアップは、Web Content Accessibility Guidelines (WCAG) 1.0 の優先度 1 ガイドラインなどのユーザー補助に関する標準に適合しない可能性があります。このコントロールのユーザー補助サポートの詳細については、「ASP.NET コントロールとユーザー補助」を参照してください。

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"> </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>   </td </tr> <tr align="center"> <td colspan="4"> <asp:Button ID="AddButton" Text="Add" OnClick="AddButton_Click" runat="server"/> </td> <td> </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"> </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>   </td </tr> <tr align="center"> <td colspan="4"> <asp:Button ID="AddButton" Text="Add" OnClick="AddButton_Click" runat="server"/> </td> <td> </td> </tr> </table> </form> </body> </html>


System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.TextBox


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TextBox クラス
アセンブリ: 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

TextBox コントロールを使用すると、ユーザーはアプリケーションにテキストを入力できます。このコントロールには、複数行の編集やパスワード文字のマスクなど、標準の Windows テキスト ボックス コントロールにはない追加機能があります。
通常、TextBox コントロールは、単一行のテキストを表示したり、入力として受け入れたりするために使用されます。Multiline プロパティと ScrollBars プロパティを使用すると、複数行のテキストを表示または入力できます。AcceptsTab プロパティと AcceptsReturn プロパティを true に設定すると、複数行の TextBox コントロールでより多くのテキストを処理できるようになります。
MaxLength プロパティを特定の文字数に設定すると、TextBox コントロールへ入力するテキストの文字数を制限できます。TextBox コントロールは、パスワードやその他の機密情報を受け入れるためにも使用できます。PasswordChar プロパティを使用すると、単一行形式のコントロールで入力した文字をマスクできます。また、CharacterCasing プロパティを使用すると、TextBox コントロールへのユーザー入力を大文字のみまたは小文字のみに制限するか、大文字と小文字の両方を受け付けるかを指定できます。
TextBox コントロールに入力するテキストを制限するには、コントロールに入力した各文字の妥当性を検査するために KeyDown イベントのイベント ハンドラを作成します。ReadOnly プロパティを true に設定すると、TextBox コントロールでデータが入力されないようにすることもできます。
![]() |
---|
Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows CE プラットフォームメモ : Pocket PC アプリケーションの場合、単一行テキスト ボックスではタブ文字は角かっこ ([]) として表示されます。ただし、Multiline が true に設定されている場合は通常どおりに表示されます。

垂直スクロール バーのある複数行 TextBox コントロールを作成するコード例を次に示します。この例では、AcceptsTab、AcceptsReturn、WordWrap の各プロパティを使用して、テキスト ドキュメントを作成しやすいように複数行テキスト ボックス コントロールを設定します。
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.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.TextBoxBase
System.Windows.Forms.TextBox
System.Windows.Forms.DataGridTextBox
System.Windows.Forms.DataGridViewTextBoxEditingControl


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTextBox クラスを検索する場合は、下記のリンクをクリックしてください。

- TextBox クラスのページへのリンク