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

備註

當文字容器的任何內容被重迭的視窗或其他物件遮蔽時,或是當具有多欄版面配置的文字容器有一或多個資料行部分捲動到檢視之外時,可能會發生不連續的文字範圍。

如果沒有顯示任何文字,則會傳回 (空的) 文字範圍。 如果文字容器是空的,或當所有文字捲動出檢視時,可以傳回這個空白範圍。

適用於

另請參閱