C# WebBrowser代码收集,方便自己
1.得到当前的滚动条位置
1 private void btGet_Click(object sender, EventArgs e) 2 { 3 HtmlDocument document = webBrowser1.Document; 4 5 txY.Text = document.GetElementsByTagName("HTML")[0].ScrollTop.ToString(); 6 txX.Text = document.GetElementsByTagName("HTML")[0].ScrollLeft.ToString(); 7 } 8 9 private void btSet_Click(object sender, EventArgs e) 10 { 11 int x = int.Parse(txX.Text); 12 int y = int.Parse(txY.Text); 13 14 webBrowser1.Document.Window.ScrollTo(x, y); 15 }
2.链接打开
1 private void webBrowser1_NewWindow(object sender, System.ComponentModel.CancelEventArgs e) 2 { 3 e.Cancel = true; 4 //页内跳转 5 //webBrowser1.Navigate(webBrowser1.StatusText); 6 //调用系统默认浏览器 7 System.Diagnostics.Process.Start(webBrowser1.StatusText); 8 }