RichTextBox.CaretPosition Właściwość
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera lub ustawia położenie karetki wejściowej.
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
Wartość właściwości
TextPointer Obiekt określający położenie karetki wejściowej.
Domyślnie karetki znajdują się w pierwszej pozycji wstawiania na początku zawartości hostowanej przez element RichTextBox. Zobacz TextPointer , aby uzyskać więcej informacji na temat terminologii dotyczącej położenia tekstu, takiej jak "pozycja wstawiania".
Wyjątki
Podjęto próbę ustawienia tej właściwości na null.
Podjęto próbę ustawienia tej właściwości na wartość, która odwołuje się do TextPointer pozycji spoza bieżącego dokumentu.
Przykłady
Poniższy przykład ilustruje użycie tej właściwości.
// 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