Hello guys,

I'm making an application for myself and I need to get the coordinates of the mouse when left click was pressed. I managed to get the coordinates when I click on the form by using

MouseUp += new MouseEventHandler(KeyCaptured);
void KeyCaptured(object sender, MouseEventArgs e)

but when I click inside the webBrowser nothing happens.
Any idea how should i capture that left click?
Thx:)

I am not sure but I've tried something that seem to work:

Set your webBrowser Uri to "about:blank" (or use any other url you want). And add "DocumentComplete" event for your webBrowser.

Add this to the DocumentComplete event:

webBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);

Put a MessageBox (for testing) inside Document_MouseUp method:

private void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
     if (e.MouseButtonsPressed == System.Windows.Forms.MouseButtons.Left)
           MessageBox.Show("You've clicked the left mouse button!");
}

Hope that helps.

Thanks

Thx mate!!!
The only way I can make it work is to declare the DocumentCompleted first

webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

and then declare the MouseUp in the DocumentCompleted

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);

        }
private void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
     if (e.MouseButtonsPressed == System.Windows.Forms.MouseButtons.Left)
           MessageBox.Show("You've clicked the left mouse button!");
}

Anyway now it works how I want to.
Thanks again!


Well it works on normal web pages but when I click on flash content the MouseUp does not happen so my problem is only half solved .:(

That is because flash objects are a plugin. What I would do is put a panel over the web browser so that it fills all but the scrollbars, have the opacity to 0, and when the right button is pressed, hide it till the button is released.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.