TextBoxBase.ScrollToCaret 메서드

정의

컨트롤의 내용을 현재 캐럿 위치까지 스크롤합니다.

public:
 void ScrollToCaret();
public void ScrollToCaret ();
member this.ScrollToCaret : unit -> unit
Public Sub ScrollToCaret ()

예제

다음 코드 예제에서는 열거형 및 ScrollToCaret 메서드를 사용하여 Keys ENTER 키를 누른 후 캐럿으로 표시되는 텍스트 삽입 지점이 항상 화면에 표시되는지 확인하는 방법을 보여 줍니다. 예제를 실행하려면 라는 컨트롤과 RichTextBox 라는 TextBox1RichTextBox1컨트롤이 포함된 TextBox 양식에 다음 코드를 붙여넣습니다. 이 예제에서는 이벤트 처리 메서드가 이벤트와 연결되어야 합니다 KeyDown .

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.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();
    }
}
'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

설명

이 메서드를 사용하면 컨트롤의 표시되는 영역 내에 있는 케어가 될 때까지 컨트롤의 내용을 스크롤할 수 있습니다. 캐리트가 컨트롤의 표시되는 영역 아래에 배치된 경우 메서드는 컨트롤 ScrollToCaret 의 아래쪽에 캐리트가 표시될 때까지 컨트롤의 내용을 스크롤합니다. 캐리트가 컨트롤의 표시되는 영역 위에 배치된 경우 이 메서드는 컨트롤의 맨 위에 캐리트가 표시될 때까지 컨트롤의 내용을 스크롤합니다. 여러 줄 텍스트 상자에서 이 메서드를 사용하여 현재 텍스트 진입점이 컨트롤의 표시되는 영역 내에 있는지 확인할 수 있습니다.

참고

컨트롤에 포커스가 없거나 컨트롤의 표시되는 영역에 이미 있는 경우 이 메서드는 영향을 주지 않습니다.

적용 대상