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

適用於

另請參閱