码迷,mamicode.com
首页 > Windows程序 > 详细

C#让WebBrowser滚动条自动上下滚动一定时间

时间:2015-02-04 10:44:56      阅读:403      评论:0      收藏:0      [点我收藏+]

标签:

namespace test_gundong
{
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);
}

private void Form1_Load(object sender, EventArgs e)
{

}
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));
}
}
}

C#让WebBrowser滚动条自动上下滚动一定时间

标签:

原文地址:http://www.cnblogs.com/wolly88/p/4271550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!