TextPatternRange.ScrollIntoView(Boolean) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
導致文字控制會垂直捲動,直到視窗顯示文字範圍。
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 以確認文字可見性。 如果文字範圍是隱藏的,文字控制項只有在隱藏文字在視窗中有錨點時才會捲動。