RichTextBox.CaretPosition 속성

정의

입력 캐럿의 위치를 가져오거나 설정합니다.

public:
 property System::Windows::Documents::TextPointer ^ CaretPosition { System::Windows::Documents::TextPointer ^ get(); void set(System::Windows::Documents::TextPointer ^ value); };
public System.Windows.Documents.TextPointer CaretPosition { get; set; }
member this.CaretPosition : System.Windows.Documents.TextPointer with get, set
Public Property CaretPosition As TextPointer

속성 값

TextPointer

입력 캐럿의 위치를 지정하는 TextPointer 개체입니다.

기본적으로 캐럿은 RichTextBox가 호스팅하는 콘텐츠의 시작 부분에 있는 첫 번째 삽입 위치에 있습니다. "삽입 위치" 등의 텍스트 위치 관련 용어에 대한 자세한 내용은 TextPointer를 참조하십시오.

예외

해당 속성을 null로 설정하려고 한 경우

이 속성을 현재 문서 외부에 있는 위치를 참조하는 TextPointer로 설정하려고 한 경우

예제

다음 예제에서는이 속성의 사용을 보여 줍니다.


// Create a new FlowDocument, and add 3 paragraphs.
FlowDocument flowDoc = new FlowDocument();
flowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 1"))); 
flowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 2"))); 
flowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 3")));
// Set the FlowDocument to be the content for a new RichTextBox.
RichTextBox rtb = new RichTextBox(flowDoc);

// Get the current caret position.
TextPointer caretPos = rtb.CaretPosition;

// Set the TextPointer to the end of the current document.
caretPos = caretPos.DocumentEnd;

// Specify the new caret position at the end of the current document.
rtb.CaretPosition = caretPos;

' Create a new FlowDocument, and add 3 paragraphs.
Dim flowDoc As New FlowDocument()
flowDoc.Blocks.Add(New Paragraph(New Run("Paragraph 1")))
flowDoc.Blocks.Add(New Paragraph(New Run("Paragraph 2")))
flowDoc.Blocks.Add(New Paragraph(New Run("Paragraph 3")))
' Set the FlowDocument to be the content for a new RichTextBox.
Dim rtb As New RichTextBox(flowDoc)

' Get the current caret position.
Dim caretPos As TextPointer = rtb.CaretPosition

' Set the TextPointer to the end of the current document.
caretPos = caretPos.DocumentEnd

' Specify the new caret position at the end of the current document.
rtb.CaretPosition = caretPos

적용 대상

추가 정보