我想添加 webBrowser 控件的点击事件。这是我的代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
HtmlDocument htmlDoc;
public Form1()
{
InitializeComponent();
OpenFileDialog open = new OpenFileDialog();
open.ShowDialog();
this.webBrowser1.Navigate(open.FileName);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.Document != null)
{
htmlDoc = webBrowser1.Document;
htmlDoc.Click += new HtmlElementEventHandler(htmlDoc_Click);
}
}
private void htmlDoc_Click(object sender, HtmlElementEventArgs e)
{
MessageBox.Show("Click");
}
}
}
我希望它显示一个 .ppt 文件。可以显示,但是当我单击 webBrowser 时,没有显示任何消息框。还有其他解决方案吗?谢谢