好的答案找到了 - 经过测试并且有效:
- 从 COM 选项卡添加一个名为:Microsoft HTML 对象库的引用
下面是一个示例代码:
您将需要两个组件:WebBrowser (webBrowser1) 和一个 TextBox (textBox1)
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
webBrowser1.LoadCompleted += new LoadCompletedEventHandler(webBrowser1_LoadCompleted);
}
private void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
{
mshtml.HTMLDocument doc;
doc = (mshtml.HTMLDocument)webBrowser1.Document;
mshtml.HTMLDocumentEvents2_Event iEvent;
iEvent = (mshtml.HTMLDocumentEvents2_Event)doc;
iEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler(ClickEventHandler);
}
private bool ClickEventHandler(mshtml.IHTMLEventObj e)
{
textBox1.Text = "Item Clicked";
return true;
}
}