Capture MouseClick or MouseDown event in WebBrowser Control

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;

}

}

}

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 3 + 2 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)