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

適用於

另請參閱