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

注解

当文本容器的任何内容被重叠窗口或其他对象遮盖时,或者当具有多列布局的文本容器有一个或多个部分滚动出视图时,可能会发生不相交的文本范围。

如果没有文本可见,则返回空) 文本范围的退化 (。 如果文本容器为空或所有文本滚动出视图,则可以返回此空范围。

适用于

另请参阅