TextPatternRange.MoveEndpointByUnit メソッド

定義

テキスト範囲の 1 つのエンドポイントを、指定された数の TextUnit の分、ドキュメントの範囲内で移動します。

public:
 int MoveEndpointByUnit(System::Windows::Automation::Text::TextPatternRangeEndpoint endpoint, System::Windows::Automation::Text::TextUnit unit, int count);
public int MoveEndpointByUnit (System.Windows.Automation.Text.TextPatternRangeEndpoint endpoint, System.Windows.Automation.Text.TextUnit unit, int count);
member this.MoveEndpointByUnit : System.Windows.Automation.Text.TextPatternRangeEndpoint * System.Windows.Automation.Text.TextUnit * int -> int
Public Function MoveEndpointByUnit (endpoint As TextPatternRangeEndpoint, unit As TextUnit, count As Integer) As Integer

パラメーター

endpoint
TextPatternRangeEndpoint

移動するエンドポイント。

unit
TextUnit

移動するためのテキスト単位。

count
Int32

移動する単位の数。 正の数はエンドポイントを前方に移動します。 負の数は後方に移動します。 0 の場合は移動されません。

戻り値

実際に移動した単位の数。エンドポイントの移動によりドキュメントの先頭または末尾に達した場合は、要求した数よりも小さくなる場合があります。

private Int32 MoveEndpointByRangeFromSelection(AutomationElement target, Int32 units)
{
    // Specify the control type we're looking for, in this case 'Document'
    PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);

    // target --> The root AutomationElement.
    AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);

    TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

    if (textpatternPattern == null)
    {
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
        return 0;
    }
    TextPatternRange[] currentSelection = textpatternPattern.GetSelection();

    return currentSelection[0].MoveEndpointByUnit(
        TextPatternRangeEndpoint.Start, TextUnit.Paragraph, units);
}
Private Function MoveEndpointByRangeFromSelection(ByVal target As AutomationElement, ByVal units As Int32) As Int32
    ' Specify the control type we're looking for, in this case 'Document'
    Dim cond As PropertyCondition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)

    ' target --> The root AutomationElement.
    Dim textProvider As AutomationElement = target.FindFirst(TreeScope.Descendants, cond)

    Dim textpatternPattern As TextPattern = CType(textProvider.GetCurrentPattern(TextPattern.Pattern), TextPattern)

    If (textpatternPattern Is Nothing) Then
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.")
        Return Nothing
    End If
    Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
    ' GetText(-1) retrieves all characters but can be inefficient
    Return currentSelection(0).MoveEndpointByUnit(TextPatternRangeEndpoint.Start, TextUnit.Paragraph, units)
End Function

注釈

テキスト範囲の内容を走査する必要がある場合、 Move メソッドを正常に実行するために、一連の手順がその背後で関係しています。

  1. テキスト範囲は正規化されます。つまり、テキスト範囲は Start エンドポイントで低次元テキスト範囲に縮小されるため、 End エンドポイントは不要になります。 この手順は、テキスト範囲が境界をまた unit ぐ状況であいまいさを取り除くために必要です。たとえば、"{The U}RL https://www.microsoft.com/ is embedded in text" ("{" と "}" がテキスト範囲のエンドポイント) です。

  2. 結果として得られる範囲は、 DocumentRange 内で、要求された unit 境界の先頭に向かって後方に移動されます。

  3. その後、この範囲は、要求された 1 つの End 境界の分、 unit エンドポイントを移動することによって、低次元テキスト範囲の状態から展開されます。

Move & ExpandToEnclosingUnit Range
テキスト範囲を Move() と ExpandToEnclosingUnit() に対して調整する方法の例

テキスト コンテナーのテキスト コンテンツ (内部テキスト) と埋め込みオブジェクト (ハイパーリンクやテーブルのセルなど) は、連続する単一のテキスト ストリームとして、UI オートメーション ツリーのコントロール ビューとコンテンツ ビューの両方で公開されます。そのため、オブジェクトの境界は無視されます。 UI オートメーション クライアントがなんらかの方法で列挙、解釈、分析を目的としてテキストを取得している場合、テキスト コンテンツを含むテーブルやその他の埋め込みオブジェクトなど、特殊なケースについて、テキスト範囲を確認する必要があります。 これを実現するには、 を呼び出 GetChildren して各埋め込みオブジェクトの を AutomationElement 取得し、 を呼び出して RangeFromChild 各要素のテキスト範囲を取得します。これは、すべてのテキスト コンテンツが取得されるまで再帰的に行われます。

埋め込みオブジェクトにまたがるテキスト範囲。
埋め込みオブジェクトとその範囲を含むテキスト ストリームの例

MoveEndpointByUnitは、指定TextUnitされた がコントロールでサポートされていない場合は、次にサポートされる最大TextUnitに延期されます。

最小単位から最大値までの順序を以下に示します。

適用対象