TextPointer.GetOffsetToPosition(TextPointer) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Geçerli TextPointer ile belirtilen ikinci bir TextPointerarasındaki simgelerin sayısını döndürür.
public:
int GetOffsetToPosition(System::Windows::Documents::TextPointer ^ position);
public int GetOffsetToPosition(System.Windows.Documents.TextPointer position);
member this.GetOffsetToPosition : System.Windows.Documents.TextPointer -> int
Public Function GetOffsetToPosition (position As TextPointer) As Integer
Parametreler
- position
- TextPointer
Uzaklığı TextPointer (simgelerde) bulmak için bir konum belirten bir.
Döndürülenler
Geçerli TextPointer ve positionarasındaki göreli simge sayısı. Negatif bir değer, geçerlinin TextPointer tarafından positionbelirtilen konumu izlediğini gösterir, 0 konumların eşit olduğunu, pozitif bir değer ise geçerlinin TextPointer tarafından positionbelirtilen konumdan önce geldiğini gösterir.
Özel durumlar
position geçerli konumla ilişkilendirilmiş metin kapsayıcısının dışında bir konum belirtir.
Örnekler
Aşağıdaki örnekte bu yöntem için bir kullanım gösterilmektedir. Örnek, iki GetOffsetToPosition örneğin uzaklıklarını bulmak için yöntemini kullanır TextPointer ve ardından seçimi bir RichTextBoxiçinde kaydedip geri yüklemek için bu bilgileri kullanır. Örnekte, öğesinin içeriğinin RichTextBox seçim kaydetme ve seçim geri yükleme arasında değişmediği varsayılır.
struct SelectionOffsets { internal int Start; internal int End; }
SelectionOffsets GetSelectionOffsetsRTB(RichTextBox richTextBox)
{
SelectionOffsets selectionOffsets;
TextPointer contentStart = richTextBox.Document.ContentStart;
// Find the offset for the starting and ending TextPointers.
selectionOffsets.Start = contentStart.GetOffsetToPosition(richTextBox.Selection.Start);
selectionOffsets.End = contentStart.GetOffsetToPosition(richTextBox.Selection.End);
return selectionOffsets;
}
void RestoreSelectionOffsetsRTB(RichTextBox richTextBox, SelectionOffsets selectionOffsets)
{
TextPointer contentStart = richTextBox.Document.ContentStart;
// Use previously determined offsets to create corresponding TextPointers,
// and use these to restore the selection.
richTextBox.Selection.Select(
contentStart.GetPositionAtOffset(selectionOffsets.Start),
contentStart.GetPositionAtOffset(selectionOffsets.End)
);
}
Private Structure SelectionOffsets
Friend Start As Integer
Friend [End] As Integer
End Structure
Private Function GetSelectionOffsetsRTB(ByVal richTextBox As RichTextBox) As SelectionOffsets
Dim selectionOffsets As SelectionOffsets
Dim contentStart As TextPointer = richTextBox.Document.ContentStart
' Find the offset for the starting and ending TextPointers.
selectionOffsets.Start = contentStart.GetOffsetToPosition(richTextBox.Selection.Start)
selectionOffsets.End = contentStart.GetOffsetToPosition(richTextBox.Selection.End)
Return selectionOffsets
End Function
Private Sub RestoreSelectionOffsetsRTB(ByVal richTextBox As RichTextBox, ByVal selectionOffsets As SelectionOffsets)
Dim contentStart As TextPointer = richTextBox.Document.ContentStart
' Use previously determined offsets to create corresponding TextPointers,
' and use these to restore the selection.
richTextBox.Selection.Select(contentStart.GetPositionAtOffset(selectionOffsets.Start), contentStart.GetPositionAtOffset(selectionOffsets.End))
End Sub
Açıklamalar
Aşağıdakilerden herhangi biri simge olarak kabul edilir:
bir TextElement öğesi için açma veya kapatma etiketi.
UIElement veya InlineUIContaineriçinde bulunan bir BlockUIContainer öğe. Bu tür bir UIElement her zaman tam olarak bir simge olarak sayılır; UIElement içerdiği ek içerik veya öğeler simge olarak sayılmaz.
Metin öğesinin Run içinde 16 bit Unicode karakteri.