2009-06-13 38 views

回答

14
ctlWebBrowser.Document.Body.ScrollIntoView(false); 

爲ScrollIntoView布爾參數()爲真與文檔的頂部對準滾動條,並假到與文檔的底部對齊滾動條。

MSDN文檔在這裏:HtmlElement.ScrollIntoView

+3

但請記住,加載到「WebBrowser」中的HTML需要包含「Body」標籤。如果您想在內容加載到WebBrowser實例後執行此操作,則最好使用`Navigated`事件,例如:webBrowser1.Navigated + =(s1,e1)=> {if(webBrowser1 .Document.Body!= null)webBrowser1.Document.Body.ScrollIntoView(false); }; – infografnet 2012-11-16 18:01:06

1

當我沒有結束元素,這個工作對我來說(VB.NET):

WebBrowser1.Document.Body.All(WebBrowser1.Document.Body.All.Count - 1).ScrollIntoView(False) 
12

我設置WebBrowser控制的DocumentText財產(與HTML和身體標記)和Document.Body.ScrollIntoView(false)方法沒有爲我工作,但這是工作:

private void ScrollToBottom() 
    { 
     // MOST IMP : processes all windows messages queue 
     Application.DoEvents(); 

     if (webBrowser1.Document != null) 
     { 
      webBrowser1.Document.Window.ScrollTo(0, webBrowser1.Document.Body.ScrollRectangle.Height); 
     } 
    } 

來源:http://kiranpatils.wordpress.com/2010/07/19/webbrowsercontrol-scroll-to-bottom/

1
wb1.Navigate("javascript:window.scroll(0,document.body.scrollHeight);") 
1

添加到user2349661的回答這是C#一樣的:

WebBrowser1.Document.Body.All[WebBrowser1.Document.Body.All.Count -1].ScrollIntoView(False) 

注:將添加爲評論,但我沒有足夠的分數!

1

使用JavaScript創建IE的安全問題

webBrowser.Navigate("javascript:window.scroll(...);") 

這是更好地利用內部文檔Completed事件一樣

webBrowser.Document.Window.ScrollTo(...) 
0

直接調用將是一個不錯的選擇:

private void Form1_Load(object sender, EventArgs e) 
{ 

webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted; 
webBrowser1.Navigate("http://stackoverflow.com/questions/990651/how-to-scroll-to-end-of-system-windows-forms-webbrowser"); 

} 


private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
{ 

WebBrowser browser = sender as WebBrowser; 

browser.Document.Body.ScrollIntoView(false); 

} 
相關問題