1

On other objects like the Forms itself MouseClick event works but when it comes to ChromiumWebBrowser the event handler simply doesn't listen any mouse clicks.

The browser is in a tab page. I tried to listen mouse clicks from there but that also didn't work.

private void ChromeBrowser_MouseClick(object sender, MouseEventArgs e)
{
     Log("Click");
}

Designer.cs:

// 
// chromeBrowser
// 
this.chromeBrowser.ActivateBrowserOnCreation = false;
this.chromeBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
this.chromeBrowser.Location = new System.Drawing.Point(3, 3);
this.chromeBrowser.Name = "chromeBrowser";
this.chromeBrowser.Size = new System.Drawing.Size(1003, 539);
this.chromeBrowser.TabIndex = 0;
this.chromeBrowser.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ChromeBrowser_MouseClick);
// 
Abdullah Akçam
  • 299
  • 4
  • 18
  • You usually need to handle click event of html elements. What's the problem which you are trying to solve? – Reza Aghaei Aug 19 '19 at 10:43
  • [Getting mouse click coordinates in a WebBrowser Document](https://stackoverflow.com/a/54232729/7444103). Of course you need to use a supported Element type. – Jimi Aug 19 '19 at 10:48
  • @RezaAghaei I need to get coordinates in chrome browser in order to simulate some key strokes and click events which depends on those coordinates. – Abdullah Akçam Aug 19 '19 at 11:57
  • So I think you can follow the approach which is shared in the linked post. – Reza Aghaei Aug 19 '19 at 13:05
  • Just one point, the event can be handled easier. You don't need to add/remove the handler by every navigation. Just one time registration would be enough, after navigating to `"about:blank"` (for `WebBrower` control or such similar address for CefSharp), get the document object and subscribe to its click event. Also to simulate click later, you probably need `Cursor.Position`. – Reza Aghaei Aug 19 '19 at 13:13
  • @RezaAghaei Unfortunately CefSharp doesn't expose DOM elements – Abdullah Akçam Aug 19 '19 at 13:19
  • Hmm, I didn't know that. I've always used WebBrowser control. – Reza Aghaei Aug 19 '19 at 13:29
  • A workaround could be trying to handle `WM_LBUTTONDOWN` using a message filter or a native window. Take a look at this issue https://github.com/cefsharp/CefSharp/issues/1098 – Reza Aghaei Aug 19 '19 at 13:55
  • CefSharp uses Javascript to access the DOM. You can apply the same concept using its methods. See the CefSharp FAQ about this: [CefSharp - Frequently asked questions](https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions) and in [CefSharp General Usage](https://github.com/cefsharp/CefSharp/wiki/General-Usage), see [Javascript integration](https://github.com/cefsharp/CefSharp/wiki/General-Usage#javascript-integration), specifically [Part #3 - Expose .NET classes to Javascript](https://github.com/cefsharp/CefSharp/wiki/General-Usage#3-how-do-you-expose-a-net-class-to-javascript). – Jimi Aug 19 '19 at 14:17

0 Answers0