共用方式為


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 會同時遵守隱藏和可見的文字。 使用者介面自動化用戶端可以檢查 IsHiddenAttribute 文字可見度。 如果文字範圍已隱藏,則只有在隱藏的文字在檢視區中有錨點時,文字控制項才會捲動。

適用於