語言

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()

傳回

可見文字集合在容器內或空陣列內。 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

備註

當文字容器中的任何內容被重疊的視窗或其他物件遮擋,或多欄配置的文字容器有一欄或多欄部分捲出時,可能會產生不相交的文字範圍。

若無文字顯示,則回傳一個退化(空)文字範圍。 當文字容器為空或所有文字滾出視窗時,這個空範圍可以回傳。

適用於

另請參閱