Reputation: 15725
I need to capture all mouse events on a .NET's WebBrowser, process them and prevent the WebBrowser from getting them. Is there any way to achieve this? I wonder if there is any way I can handle mouse events if the control is disabled.
Upvotes: 0
Views: 2324
Reputation: 81
There IS a solution to this. You need to capture the mouse events that are associated with the Document object that is associated with the webBrowser control.
After the DocumentCompleted event occurs, and inside you DocumentCompleted event handler, do the following:
myWebBrowser.Document.MouseDown += new HtmlElementEventHandler(myMouseDown);
and have the related handler:
void myMouseDown(object sender, HtmlElementEventArgs e)
{
your code to handle the mouse event... such as ...
if (e.MouseButtonsPressed == MouseButtons.Right)
{
}
}
Upvotes: 3
Reputation: 942267
You'll have to override WndProc() to intercept the mouse messages. Like this:
using System;
using System.Windows.Forms;
class MyBrowser : WebBrowser {
protected override void WndProc(ref Message m) {
if (m.Msg >= 0x200 && m.Msg <= 0x20a) {
// Handle mouse messages
//...
}
else base.WndProc(ref m);
}
}
Upvotes: 3