我是 C# 的初学者,我有一个问题。每次在执行搜索请求后,我需要在 webBrowser 控件中发现一个事件时弹出一个消息框,此时将选择该事件。我正在使用计时器来刷新 webBrowser 并再次启动搜索。这就像一个通知系统。
using System;
using System.Windows.Forms;
using mshtml;
namespace websearch
{
public partial class Form1 : Form
{
Timer temp = new Timer();
//Timer refreshh = new Timer();
public Form1()
{
InitializeComponent();
temp.Tick += new EventHandler(refreshh_Tick);
temp.Interval = 1000 * 5;
temp.Enabled = true;
temp.Start();
WebBrowser1.Navigate("http://stackoverflow.com/");
}
void refreshh_Tick(object sender, EventArgs e)
{
WebBrowser1.Refresh();
WebBrowser1.DocumentCompleted += Carder_DocumentCompleted;
}
private void Carder_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
FindNext("C#", WebBrowser1);
temp.Tick += refreshh_Tick;
}
public void FindNext(string text, WebBrowser webBrowser2)
{
IHTMLDocument2 doc = webBrowser2.Document.DomDocument as IHTMLDocument2;
IHTMLSelectionObject sel = doc.selection;
IHTMLTxtRange rng = sel.createRange() as IHTMLTxtRange;
rng.collapse(false); // collapse the current selection so we start from the end of the previous range
if (rng.findText(text))
{
rng.select();
MessageBox.Show("Theire are new C# Question");
}
}
}
}