2009-06-13 60 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); 

} 
相关问题