I'm trying to figure out how can i get the click event position using DotNetBrowser.
I know how to get a node name for a given location using X,Y points but I need to get it from a click event in browser.
Any idea?
It's Eugene here. I work with the team which created DotNetBrowser.
To get the mouse click position you can use the MouseDown
event. I have provided the samples below.
Windows Forms:
public partial class MainForm : Form
{
private WinFormsBrowserView browserView;
public MainForm()
{
InitializeComponent();
browserView = new WinFormsBrowserView() {Dock = DockStyle.Fill};
browserView.MouseDown += BrowserView_MouseDown;
this.Controls.Add(browserView);
}
private void BrowserView_MouseDown(object sender, MouseEventArgs e)
{
int clickX = e.X;
int clickY = e.Y;
}
}
WPF:
public partial class MainWindow : Window
{
private WPFBrowserView browserView;
public MainWindow()
{
InitializeComponent();
browserView = new WPFBrowserView();
browserView.MouseDown += BrowserView_MouseDown;
this.MainGrid.Children.Add(browserView);
}
private void BrowserView_MouseDown(object sender, MouseButtonEventArgs e)
{
Point clickPoint = e.GetPosition(browserView);
double clickX = clickPoint.X;
double clickY = clickPoint.Y;
}
}
After that you can get the node for the obtained location using the Browser.NodeAtPoint
method:
DOMNodeAtPoint nodeAtPoint = browserView.Browser.NodeAtPoint((int)clickX, (int)clickY);