TextPatternRange.ScrollIntoView(Boolean) 方法

定义

导致文本控件垂直滚动,直到文本范围在视区中可见。

public:
 void ScrollIntoView(bool alignToTop);
public void ScrollIntoView (bool alignToTop);
member this.ScrollIntoView : bool -> unit
Public Sub ScrollIntoView (alignToTop As Boolean)

参数

alignToTop
Boolean

如果文本控件应该滚动以便文本范围与视区顶部对齐,则为 true;如果应该与视区底部对齐,则为 false

例外

如果控件不支持滚动。

示例

private void ScrollToSelection(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;
    }
    TextPatternRange[] currentSelection = textpatternPattern.GetSelection();

    currentSelection[0].ScrollIntoView(true);
}
Private Sub ScrollToSelection(ByVal target As AutomationElement)
    ' 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
    End If
    Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
    currentSelection(0).ScrollIntoView(True)
End Sub

注解

ScrollIntoView 尊重隐藏文本和可见文本。 UI 自动化客户端可以检查 文本IsHiddenAttribute可见性。 如果文本范围处于隐藏状态,则仅当隐藏的文本在视区中具有定位点时,文本控件才会滚动。

适用于