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

Dim instance As RichTextBox Dim value As Integer value = instance.MaxLength instance.MaxLength = value
public override function get MaxLength () : int public override function set MaxLength (value : int)
コントロールに入力できる文字数。既定値は MaxValue です。


このプロパティが 0 に設定されている場合、コントロールに入力できるテキストの最大の長さは 64 KB 分文字になります。このプロパティは、通常、RichTextBox に単一行のリッチ テキスト形式 (RTF: Rich Text Format) テキストを表示するときに使用します。このプロパティを使用すると、郵便番号や電話番号などの値を入力するコントロールのテキストの長さや、データベースにデータを入力するときのテキストの長さを制限できます。コントロールに入力するテキストの長さを、データベースの該当フィールドの最大の長さ以下に制限できます。
![]() |
---|
コードでは、Text プロパティの値を MaxLength プロパティで指定した値よりも長い値に設定できます。このプロパティは、実行時にコントロールに入力されるテキストにだけ影響します。 |

MaxLength プロパティを使用して、RichTextBox コントロールに割り当てられているテキストが MaxLength プロパティで指定した値よりも長いかどうかを確認する方法を次のコード例に示します。この例では、テキストの方が長くない場合は、SelectedText プロパティを使用してコントロールにテキストを割り当てます。この例では、richTextBox1 という名前の RichTextBox コントロールがフォームに追加されており、この例のメソッドがコントロール内に貼り付けられるテキストをパラメータに指定して呼び出される必要があります。また、RichTextBox へのテキスト入力を制限する値を MaxLength プロパティに設定する必要もあります。
Private Sub AddMyText(ByVal textToAdd As String) ' Determine if the text to add is larger than the max length property. If textToAdd.Length > richTextBox1.MaxLength Then ' Alert user text is too large. MessageBox.Show("The text is too large to addo to the RichTextBox") ' Add the text to be added to the control. Else richTextBox1.SelectedText = textToAdd End If End Sub
private void AddMyText(string textToAdd) { // Determine if the text to add is larger than the max length property. if (textToAdd.Length > richTextBox1.MaxLength) // Alert user text is too large. MessageBox.Show("The text is too large to addo to the RichTextBox"); else // Add the text to be added to the control. richTextBox1.SelectedText = textToAdd; }
private: void AddMyText( String^ textToAdd ) { // Determine if the text to add is larger than the max length property. if ( textToAdd->Length > richTextBox1->MaxLength ) // Alert user text is too large. MessageBox::Show( "The text is too large to add to the RichTextBox" ); // Add the text to be added to the control. else richTextBox1->SelectedText = textToAdd; }
private void AddMyText(String textToAdd) { // Determine if the text to add is larger than the max length property. if (textToAdd.get_Length() > richTextBox1.get_MaxLength()) { // Alert user text is too large. MessageBox.Show("The text is too large to addo to the RichTextBox"); } else { // Add the text to be added to the control. richTextBox1.set_SelectedText(textToAdd); } } //AddMyText

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

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