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


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 内)



TextBox コンストラクタを使用して、ページに TextBox コントロールを動的に追加する方法を次のコード例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Protected Sub Page_Load(sender As Object, e As EventArgs) ' Create UserTextBox TextBox control. Dim UserTextBox As New TextBox() ' Configure the UserTextBox TextBox control. UserTextBox.ID = "UserTextBox" UserTextBox.Columns = 50 ' Add UserTextBox TextBox control to the Controls collection ' of the TextBoxControlPlaceHolder PlaceHolder control. TextBoxControlPlaceHolder.Controls.Add(UserTextBox) End Sub Protected Sub Submit_Click(sender As Object, e As EventArgs) ' Retrieve the UserTextBox TextBox control from the TextBoxControlPlaceHolder ' PlaceHolder control. Dim TempTextBox As TextBox = CType(TextBoxControlPlaceHolder.FindControl("UserTextBox"), TextBox) ' Display the Text property. Message.Text = "The TextBox control above is dynamically generated. <br> You entered: " & _ TempTextBox.Text End Sub </script> </head> <body> <form runat="server"> <h3> TextBox Constructor Example </h3> Enter some text and click the Submit button. <br><br> <asp:PlaceHolder ID="TextBoxControlPlaceHolder" runat="server"/> <br><br> <asp:Button ID="SubmitButton" Text="Submit" OnClick="Submit_Click" runat="server"/> <br><br> <asp:Label ID="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> protected void Page_Load(Object sender, EventArgs e) { // Create UserTextBox TextBox control. TextBox UserTextBox = new TextBox(); // Configure the UserTextBox TextBox control. UserTextBox.ID = "UserTextBox"; UserTextBox.Columns = 50; // Add UserTextBox TextBox control to the Controls collection // of the TextBoxControlPlaceHolder PlaceHolder control. TextBoxControlPlaceHolder.Controls.Add(UserTextBox); } protected void Submit_Click(Object sender, EventArgs e) { // Retrieve the UserTextBox TextBox control from the TextBoxControlPlaceHolder // PlaceHolder control. TextBox TempTextBox = (TextBox)TextBoxControlPlaceHolder.FindControl("UserTextBox"); // Display the Text property. Message.Text = "The TextBox control above is dynamically generated. <br> You entered: " + TempTextBox.Text; } </script> </head> <body> <form runat="server"> <h3> TextBox Constructor Example </h3> Enter some text and click the Submit button. <br><br> <asp:PlaceHolder ID="TextBoxControlPlaceHolder" runat="server"/> <br><br> <asp:Button ID="SubmitButton" Text="Submit" OnClick="Submit_Click" runat="server"/> <br><br> <asp:Label ID="Message" runat="server"/> </form> </body> </html>

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 内)


親コンテナ コントロールで、TextBox の色およびフォントの設定を定義します。

TextBox コントロールの新しいインスタンスを作成し、文字列をコントロールの Text プロパティに代入するコード例を次に示します。
Public Sub CreateMyTextBoxControl() ' Create a new TextBox control using this constructor. Dim textBox1 As New TextBox() ' Assign a string of text to the new TextBox control. textBox1.Text = "Hello World!" ' Code goes here to add the control to the form's control collection. End Sub
public void CreateMyTextBoxControl() { // Create a new TextBox control using this constructor. TextBox textBox1 = new TextBox(); // Assign a string of text to the new TextBox control. textBox1.Text = "Hello World!"; // Code goes here to add the control to the form's control collection. }
public: void CreateMyTextBoxControl() { // Create a new TextBox control using this constructor. TextBox^ textBox1 = gcnew TextBox; // Assign a string of text to the new TextBox control. textBox1->Text = "Hello World!"; // Code goes here to add the control to the form's control collection. }
public void CreateMyTextBoxControl() { // Create a new TextBox control using this constructor. TextBox textBox1 = new TextBox(); // Assign a string of text to the new TextBox control. textBox1.set_Text("Hello World!"); // Code goes here to add the control to the form's control collection. } //CreateMyTextBoxControl

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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