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



AppendText メソッドと TextLength プロパティを使用して、TextBox 間でテキストをコピーする方法を次のコード例に示します。この例では、textBox1 および textBox2 という名前の 2 つの TextBox コントロールがフォームに追加されており、textBox1 の Text プロパティにテキストが割り当てられている必要があります。
Private Sub AppendTextBox1Text() ' Determine if text is selected in textBox1. If textBox1.SelectionLength = 0 Then ' No selection made, return. Return End If ' Determine if the text being appended to textBox2 exceeds the MaxLength property. If textBox1.SelectedText.Length + textBox2.TextLength > textBox2.MaxLength Then MessageBox.Show("The text to paste in is larger than the maximum number of characters allowed") ' Append the text from textBox1 into textBox2. Else textBox2.AppendText(textBox1.SelectedText) End If End Sub
private void AppendTextBox1Text() { // Determine if text is selected in textBox1. if(textBox1.SelectionLength == 0) // No selection made, return. return; // Determine if the text being appended to textBox2 exceeds the MaxLength property. if((textBox1.SelectedText.Length + textBox2.TextLength) > textBox2.MaxLength) MessageBox.Show("The text to paste in is larger than the maximum number of characters allowed"); else // Append the text from textBox1 into textBox2. textBox2.AppendText(textBox1.SelectedText); }
void AppendTextBox1Text() { // Determine if text is selected in textBox1. if ( textBox1->SelectionLength == 0 ) // No selection made, return. return; // Determine if the text being appended to textBox2 exceeds the MaxLength property. if ( (textBox1->SelectedText->Length + textBox2->TextLength) > textBox2->MaxLength ) MessageBox::Show( "The text to paste in is larger than the maximum number of characters allowed" ); // Append the text from textBox1 into textBox2. else textBox2->AppendText( textBox1->SelectedText ); }
private void AppendTextBox1Text() { // Determine if text is selected in textBox1. if (textBox1.get_SelectionLength() == 0) { // No selection made, return. return; } // Determine if the text being appended to textBox2 exceeds the MaxLength // property. if (textBox1.get_SelectedText().get_Length() + textBox2.get_TextLength() > textBox2.get_MaxLength()) { MessageBox.Show("The text to paste in is larger than the maximum" + " number of characters allowed"); } else { // Append the text from textBox1 into textBox2. textBox2.AppendText(textBox1.get_SelectedText()); } } //AppendTextBox1Text

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.TextLength プロパティを検索する場合は、下記のリンクをクリックしてください。

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