TextPointer.GetPositionAtOffset メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コンテンツの先頭から、指定したオフセットで示される位置に 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
返されるTextPointerの論理方向を指定するLogicalDirection値の 1 つ。
返品
指定したオフセットによって示される位置への TextPointer 。オフセットがコンテンツの末尾を越えた場合に null 。
注釈
次のいずれかがシンボルと見なされます。
TextElement要素の開始タグまたは終了タグ。
InlineUIContainerまたはBlockUIContainerに含まれるUIElement要素。 このような UIElement は常に 1 つのシンボルとしてカウントされます。 UIElement に含まれる追加のコンテンツまたは要素はシンボルとしてカウントされません。
テキスト Run 要素内の 16 ビット Unicode 文字。
こちらもご覧ください
適用対象
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 メソッドを使用してメソッドのペアを実装し、1 つはホスティング 段落を基準にして指定した位置へのオフセットを計算し、もう 1 つは指定した段落内の指定したオフセットに 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要素の開始タグまたは終了タグ。
InlineUIContainerまたはBlockUIContainerに含まれるUIElement要素。 このような UIElement は常に 1 つのシンボルとしてカウントされます。 UIElement に含まれる追加のコンテンツまたは要素はシンボルとしてカウントされません。
テキスト Run 要素内の 16 ビット Unicode 文字。