HtmlElement.ScrollIntoView(Boolean) 方法

定义

滚动包含此元素的文档,直到此元素的上边缘或下边缘与此文档窗口对齐为止。

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

参数

alignWithTop
Boolean

如果为 true,则对象顶部将显示在窗口的顶部。 如果为 false,则对象底部将显示在窗口的底部。

示例

下面的代码示例按名称查找元素,并滚动浏览页面,使元素的顶部与可见页面的顶部对齐。

private void ScrollToElement(String elemName)
{
    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        HtmlElementCollection elems = doc.All.GetElementsByName(elemName);
        if (elems != null && elems.Count > 0)
        {
            HtmlElement elem = elems[0];

            elem.ScrollIntoView(true);
        }
    }
}
Private Sub ScrollToElement(ByVal ElemName As String)
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Dim Elems As HtmlElementCollection = .All.GetElementsByName(ElemName)
            If (Not Elems Is Nothing And Elems.Count > 0) Then
                Dim Elem As HtmlElement = Elems(0)

                Elem.ScrollIntoView(True)
            End If
        End With
    End If
End Sub

适用于

另请参阅