我试图找出我可以启用一个计时器,并设置其间隔为1000时,网页完成加载。
下面是我目前尝试的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("website.com");
webBrowser1.ScriptErrorsSuppressed = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("brukernavn")[0].SetAttribute("value", textBox1.Text);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("passord")[0].SetAttribute("value", textBox2.Text);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("login_buton")[0].InvokeMember("click");
timer1.Enabled = true;
timer1.Interval = 7000;
}
private void timer1_Tick(object sender, EventArgs e)
{
webBrowser1.Navigate("website.com/mygambling.php");
//Here I need a code to enable timer2 with interval 1000 when the website is finished loading
}
private void timer2_Tick(object sender, EventArgs e)
{
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("bet")[0].SetAttribute("value", 250);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("start")[0].InvokeMember("click");
}
}
}
因此,我的问题是如何启用timer2,并在页面加载完成时将timer2的时间间隔设置为1000?
1条答案
按热度按时间c90pui9n1#
您已经知道如何启用计时器。Web浏览器有一个DocumentCompleted事件,您可以在其中订阅。这将帮助您确定页面加载完成的时间: