zoukankan      html  css  js  c++  java
  • C#让WebBrowser滚动条自动上下滚动一定时间

    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++异常:exception
    C++关键字:explicit
    C++关键字:重学记录
    Unity jointmoto
    hashtable和hashmap
    Spring MVC 笔记 概述
    SQL上门2
    面试:A
    Java 初学者
    SQL上门
  • 原文地址:https://www.cnblogs.com/wolly88/p/4271550.html
Copyright © 2011-2022 走看看