Capture MouseClick or MouseDown event in WebBrowser Control
Found a solution to this issue.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WebBrowserTest
{
public partial class Form1 : Form
{
HtmlDocument htmlDoc;
public Form1()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.Document != null)
{
htmlDoc = webBrowser1.Document;
htmlDoc.Click += htmlDoc_Click;
htmlDoc.MouseDown += htmlDoc_MouseDown;
htmlDoc.MouseMove += htmlDoc_MouseMove;
htmlDoc.ContextMenuShowing += htmlDoc_ContextMenuShowing;
}
}
void htmlDoc_ContextMenuShowing(object sender, HtmlElementEventArgs e)
{
// stop the right mouse Menu
e.ReturnValue = false;
}
void htmlDoc_MouseMove(object sender, HtmlElementEventArgs e)
{
Console.WriteLine(“Mouse Move");
}
void htmlDoc_MouseDown(object sender, HtmlElementEventArgs e)
{
Console.WriteLine(“Mouse Down");
}
void htmlDoc_Click(object sender, HtmlElementEventArgs e)
{
Console.WriteLine(“Mouse Click");
// stop mouse events moving on to the HTML doc
e.ReturnValue = false;
}
}
}