TextBoxBase.MaxLength プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As TextBoxBase Dim value As Integer value = instance.MaxLength instance.MaxLength = value
[LocalizableAttribute(true)] public: virtual property int MaxLength { int get (); void set (int value); }
コントロールに入力できる文字数。既定値は 32767 です。


このプロパティを使用すると、郵便番号や電話番号などの値を入力するコントロールのテキストの長さや、データベースにデータを入力するときのテキストの長さを制限できます。コントロールに入力するテキストの長さを、データベースの該当フィールドの最大の長さ以下に制限できます。
![]() |
---|
コードでは、Text プロパティの値を MaxLength プロパティで指定した値よりも長い値に設定できます。このプロパティは、実行時にコントロールに入力されるテキストにだけ影響します。 |
Windows NT 4.0, Windows 2000, Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 プラットフォームメモ : 単一行テキスト ボックス コントロールで MaxLength プロパティを 0 に設定した場合、ユーザーが入力できる最大文字数は、2147483646 または使用可能なメモリに応じたサイズのうち、いずれか小さい数となります。複数行テキスト ボックス コントロールの場合、ユーザーが入力できる最大文字数は、4294967295 または使用可能なメモリに応じたサイズのうち、いずれか小さい数となります。
Windows Millennium Edition プラットフォームメモ : 単一行テキスト ボックス コントロールで MaxLength プロパティを 0 に設定した場合、ユーザーが入力できる最大文字数は、32,766 または使用可能なメモリに応じたサイズのうち、いずれか小さい数となります。複数行テキスト ボックス コントロールの場合、ユーザーが入力できる最大文字数は、65,535 または使用可能なメモリに応じたサイズのうち、いずれか小さい数となります。

派生クラス TextBox を使用して、パスワードを受け入れるために使用されるテキスト ボックスを作成するコード例を次に示します。この例では、CharacterCasing プロパティを使用して、入力されたすべての文字を大文字に変更します。また、MaxLength プロパティを使用して、パスワード長を 8 文字に制限します。この例では、TextAlign プロパティも使用して、TextBox コントロールの中央にパスワードを配置します。
Public Sub CreateMyPasswordTextBox() ' Create an instance of the TextBox control. Dim textBox1 As New TextBox() ' Set the maximum length of text in the control to eight. textBox1.MaxLength = 8 ' Assign the asterisk to be the password character. textBox1.PasswordChar = "*"c ' Change all text entered to be uppercase. textBox1.CharacterCasing = CharacterCasing.Upper ' Align the text in the center of the TextBox control. textBox1.TextAlign = HorizontalAlignment.Center End Sub
public void CreateMyPasswordTextBox() { // Create an instance of the TextBox control. TextBox textBox1 = new TextBox(); // Set the maximum length of text in the control to eight. textBox1.MaxLength = 8; // Assign the asterisk to be the password character. textBox1.PasswordChar = '*'; // Change all text entered to be uppercase. textBox1.CharacterCasing = CharacterCasing.Upper; // Align the text in the center of the TextBox control. textBox1.TextAlign = HorizontalAlignment.Center; }
public: void CreateMyPasswordTextBox() { // Create an instance of the TextBox control. TextBox^ textBox1 = gcnew TextBox; // Set the maximum length of text in the control to eight. textBox1->MaxLength = 8; // Assign the asterisk to be the password character. textBox1->PasswordChar = '*'; // Change all text entered to be uppercase. textBox1->CharacterCasing = CharacterCasing::Upper; // Align the text in the center of the TextBox control. textBox1->TextAlign = HorizontalAlignment::Center; }
public void CreateMyPasswordTextBox() { // Create an instance of the TextBox control. TextBox textBox1 = new TextBox(); // Set the maximum length of text in the control to eight. textBox1.set_MaxLength(8); // Assign the asterisk to be the password character. textBox1.set_PasswordChar('*'); // Change all text entered to be uppercase. textBox1.set_CharacterCasing(CharacterCasing.Upper); // Align the text in the center of the TextBox control. textBox1.set_TextAlign(HorizontalAlignment.Center); } //CreateMyPasswordTextBox

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に収録されているすべての辞書からTextBoxBase.MaxLength プロパティを検索する場合は、下記のリンクをクリックしてください。

- TextBoxBase.MaxLength プロパティのページへのリンク