Share via


TextPattern.GetVisibleRanges メソッド

定義

テキスト コンテナーから非結合テキスト範囲の配列を取得します。それぞれのテキスト範囲は部分的に表示されている最初の行から始まり、部分的に表示されている最後の行の末尾で終わります。

public:
 cli::array <System::Windows::Automation::Text::TextPatternRange ^> ^ GetVisibleRanges();
public System.Windows.Automation.Text.TextPatternRange[] GetVisibleRanges ();
member this.GetVisibleRanges : unit -> System.Windows.Automation.Text.TextPatternRange[]
Public Function GetVisibleRanges () As TextPatternRange()

戻り値

TextPatternRange[]

コンテナーまたは空の配列に含まれる表示テキスト範囲のコレクション。 Null は返されません。

private TextPatternRange[] CurrentVisibleRanges(AutomationElement target)
{
    // 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 null;
    }
    return textpatternPattern.GetVisibleRanges();
}
Private Function CurrentVisibleRanges(ByVal target As AutomationElement) As TextPatternRange()
    ' 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

    Return textpatternPattern.GetVisibleRanges()
End Function

注釈

結合されていないテキスト範囲は、テキスト コンテナーの内容が重なるウィンドウまたはその他のオブジェクトによって隠されている場合、または複数列レイアウトのテキスト コンテナーで 1 つ以上の列が部分的にスクロールされた場合に発生する可能性があります。

テキストが表示されない場合は、縮退 (空) のテキスト範囲が返されます。 この空の範囲は、テキスト コンテナーが空の場合、またはすべてのテキストが表示されなくなっている場合に返されます。

適用対象

こちらもご覧ください