TextPointer.GetPositionAtOffset Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
TextPointer Возвращает позицию, указанную указанным смещением в символах с начала содержимого.
Перегрузки
| Имя | Описание |
|---|---|
| GetPositionAtOffset(Int32, LogicalDirection) |
TextPointer Возвращает позицию, указанную указанным смещением, в символах с начала текущего TextPointer и в указанном направлении. |
| GetPositionAtOffset(Int32) |
TextPointer Возвращает положение, указанное смещением, в символах с начала текущегоTextPointer. |
GetPositionAtOffset(Int32, LogicalDirection)
TextPointer Возвращает позицию, указанную указанным смещением, в символах с начала текущего TextPointer и в указанном направлении.
public:
System::Windows::Documents::TextPointer ^ GetPositionAtOffset(int offset, System::Windows::Documents::LogicalDirection direction);
public System.Windows.Documents.TextPointer GetPositionAtOffset(int offset, System.Windows.Documents.LogicalDirection direction);
member this.GetPositionAtOffset : int * System.Windows.Documents.LogicalDirection -> System.Windows.Documents.TextPointer
Public Function GetPositionAtOffset (offset As Integer, direction As LogicalDirection) As TextPointer
Параметры
- offset
- Int32
Смещение в символах, для которых необходимо вычислить и вернуть позицию. Если смещение отрицательное, возвращенный TextPointer предшествует текущему TextPointer; в противном случае он следует.
- direction
- LogicalDirection
Одно из LogicalDirection значений, указывающее логическое направление возвращаемого TextPointerобъекта.
Возвращаемое значение
Положение TextPointer , указанное указанным смещением, или null если смещение распространяется за конец содержимого.
Комментарии
Любой из следующих элементов считается символом:
Открывающий или закрывающий тег элемента TextElement .
Элемент UIElement , содержащийся в объекте InlineUIContainer или BlockUIContainer. Обратите внимание, что такое UIElement всегда учитывается как один символ; любое дополнительное содержимое или элементы, содержащиеся в нем UIElement , не считаются символами.
16-разрядный символ Юникода внутри текстового Run элемента.
См. также раздел
Применяется к
GetPositionAtOffset(Int32)
TextPointer Возвращает положение, указанное смещением, в символах с начала текущегоTextPointer.
public:
System::Windows::Documents::TextPointer ^ GetPositionAtOffset(int offset);
public System.Windows.Documents.TextPointer GetPositionAtOffset(int offset);
member this.GetPositionAtOffset : int -> System.Windows.Documents.TextPointer
Public Function GetPositionAtOffset (offset As Integer) As TextPointer
Параметры
- offset
- Int32
Смещение в символах, для которых необходимо вычислить и вернуть позицию. Если смещение отрицательное, позиция вычисляется в логическом направлении, противоположном свойству LogicalDirection .
Возвращаемое значение
Позиция TextPointer , указанная указанным смещением, или null если соответствующая позиция не найдена.
Примеры
В следующем примере демонстрируется использование этого метода. В примере используется GetPositionAtOffset метод для реализации пары методов, один для вычисления смещения до указанной позиции относительно любого абзаца размещения, а другой — для возврата TextPointer указанного смещения в указанном абзаце.
// Returns the offset for the specified position relative to any containing paragraph.
int GetOffsetRelativeToParagraph(TextPointer position)
{
// Adjust the pointer to the closest forward insertion position, and look for any
// containing paragraph.
Paragraph paragraph = (position.GetInsertionPosition(LogicalDirection.Forward)).Paragraph;
// Some positions may be not within any Paragraph;
// this method returns an offset of -1 to indicate this condition.
return (paragraph == null) ? -1 : paragraph.ContentStart.GetOffsetToPosition(position);
}
// Returns a TextPointer to a specified offset into a specified paragraph.
TextPointer GetTextPointerRelativeToParagraph(Paragraph paragraph, int offsetRelativeToParagraph)
{
// Verify that the specified offset falls within the specified paragraph. If the offset is
// past the end of the paragraph, return a pointer to the farthest offset position in the paragraph.
// Otherwise, return a TextPointer to the specified offset in the specified paragraph.
return (offsetRelativeToParagraph > paragraph.ContentStart.GetOffsetToPosition(paragraph.ContentEnd))
? paragraph.ContentEnd : paragraph.ContentStart.GetPositionAtOffset(offsetRelativeToParagraph);
}
' Returns the offset for the specified position relative to any containing paragraph.
Private Function GetOffsetRelativeToParagraph(ByVal position As TextPointer) As Integer
' Adjust the pointer to the closest forward insertion position, and look for any
' containing paragraph.
Dim paragraph As Paragraph = (position.GetInsertionPosition(LogicalDirection.Forward)).Paragraph
' Some positions may be not within any Paragraph
' this method returns an offset of -1 to indicate this condition.
Return If((paragraph Is Nothing), -1, paragraph.ContentStart.GetOffsetToPosition(position))
End Function
' Returns a TextPointer to a specified offset into a specified paragraph.
Private Function GetTextPointerRelativeToParagraph(ByVal paragraph As Paragraph, ByVal offsetRelativeToParagraph As Integer) As TextPointer
' Verify that the specified offset falls within the specified paragraph. If the offset is
' past the end of the paragraph, return a pointer to the farthest offset position in the paragraph.
' Otherwise, return a TextPointer to the specified offset in the specified paragraph.
Return If((offsetRelativeToParagraph > paragraph.ContentStart.GetOffsetToPosition(paragraph.ContentEnd)), paragraph.ContentEnd, paragraph.ContentStart.GetPositionAtOffset(offsetRelativeToParagraph))
End Function
Комментарии
Любой из следующих элементов считается символом:
Открывающий или закрывающий тег элемента TextElement .
Элемент UIElement , содержащийся в объекте InlineUIContainer или BlockUIContainer. Обратите внимание, что такое UIElement всегда учитывается как один символ; любое дополнительное содержимое или элементы, содержащиеся в нем UIElement , не считаются символами.
16-разрядный символ Юникода внутри текстового Run элемента.