您的位置:首页 > 其它

webbrowser 自动滚动网页

2015-09-12 11:22 344 查看
public partial class Form1 : Form
{
int current = 0;
Timer timeDown = new Timer();
Timer timeUp = new Timer();

public Form1()
{
InitializeComponent();

webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
webBrowser1.Navigate("http://www.yahoo.com.cn");

timeDown.Interval = 100;
timeDown.Tick += new EventHandler(timeDown_Tick);
timeUp.Interval = 100;
timeUp.Tick += new EventHandler(timeUp_Tick);

}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
current = 0;
timeDown.Enabled = true;
}
void timeDown_Tick(object sender, EventArgs e)
{
HtmlDocument doc = webBrowser1.Document;
int height = webBrowser1.Document.Body.ScrollRectangle.Height;
current += height / 100;
if (current >= height)
{
current = height;
timeDown.Enabled = false;
timeUp.Enabled = true;
}

doc.Window.ScrollTo(new Point(0, current));
}
void timeUp_Tick(object sender, EventArgs e)
{
HtmlDocument doc = webBrowser1.Document;
int height = webBrowser1.Document.Body.ScrollRectangle.Height;
current -= height / 100;
if (current <= 0)
{
current = 0;
timeUp.Enabled = false;
}
doc.Window.ScrollTo(new Point(0, current));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: