TextBoxBase.ScrollToCaret メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TextBoxBase.ScrollToCaret メソッドの意味・解説 

TextBoxBase.ScrollToCaret メソッド

コントロールの内容を現在のカレットの位置までスクロールします。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Sub ScrollToCaret
Dim instance As TextBoxBase

instance.ScrollToCaret
public void ScrollToCaret ()
public:
void ScrollToCaret ()
public void ScrollToCaret ()
public function 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

TextBoxBase.ScrollToCaret メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TextBoxBase.ScrollToCaret メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS