TextBoxBase.ScrollToCaret メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


このメソッドを使用すると、キャレットがコントロールの表示領域内に入るまでコントロールの内容をスクロールできるようになります。カレットがコントロールの表示領域より下にある場合、ScrollToCaret メソッドは、カレットがコントロールの一番下に表示されるまでコントロールの内容をスクロールします。カレットがコントロールの表示領域より上にある場合、このメソッドは、カレットがコントロールの一番上に表示されるまでコントロールの内容をスクロールします。このメソッドを複数行テキスト ボックスで使用すると、テキスト エントリ ポイントをコントロールの表示領域内に確実に入れられます。
![]() |
---|
コントロールにフォーカスがない場合、またはカレットが既にコントロールの表示領域に位置している場合、このメソッドは無効です。 |

Keys 列挙体と ScrollToCaret メソッドの使用方法を示すコード例を次に示します。この例を実行するには、TextBox1 という名前の TextBox コントロールと RichTextBox1 という名前の RichTextBox コントロールが配置されているフォームに次のコードを貼り付けます。この例では、イベントを処理するメソッドが KeyDown イベントに関連付けられている必要があります。
'Handles the Enter key being pressed while TextBox1 has focus. Private Sub TextBox1_KeyDown(ByVal sender As Object, _ ByVal e As KeyEventArgs) Handles TextBox1.KeyDown TextBox1.HideSelection = False If e.KeyCode = Keys.Enter Then e.Handled = True ' Copy the text from TextBox1 to RichTextBox1, add a CRLF after ' the copied text, and keep the caret in view. RichTextBox1.SelectedText = TextBox1.Text + _ Microsoft.VisualBasic.vbCrLf RichTextBox1.ScrollToCaret() End If End Sub
//Handles the Enter key being pressed while TextBox1 has focus. private void TextBox1_KeyDown(object sender, KeyEventArgs e) { TextBox1.HideSelection = false; if (e.KeyCode==Keys.Enter) { e.Handled = true; // Copy the text from TextBox1 to RichTextBox1, add a CRLF after // the copied text, and keep the caret in view. RichTextBox1.SelectedText = TextBox1.Text + "\r\n"; RichTextBox1.ScrollToCaret(); } }
private: //Handles the Enter key being pressed while TextBox1 has focus. void TextBox1_KeyDown( Object^ /*sender*/, KeyEventArgs^ e ) { TextBox1->HideSelection = false; if ( e->KeyCode == Keys::Enter ) { e->Handled = true; // Copy the text from TextBox1 to RichTextBox1, add a CRLF after // the copied text, and keep the caret in view. RichTextBox1->SelectedText = String::Concat( TextBox1->Text, "\r\n" ); RichTextBox1->ScrollToCaret(); } }
//Handles the Enter key being pressed while TextBox1 has focus. private void textBox1_KeyDown(Object sender, KeyEventArgs e) { textBox1.set_HideSelection(false); if (e.get_KeyCode().Equals(Keys.Enter)) { e.set_Handled(true); // Copy the text from textBox1 to richTextBox1, add a CRLF after // the copied text, and keep the caret in view. richTextBox1.set_SelectedText(textBox1.get_Text() + "\r\n"); richTextBox1.ScrollToCaret(); } } //textBox1_KeyDown

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.ScrollToCaret メソッドを検索する場合は、下記のリンクをクリックしてください。

- TextBoxBase.ScrollToCaret メソッドのページへのリンク