0

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?

1 Answers1

0

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);
Eugene Yakush
  • 259
  • 4
  • 6
  • Hi, thanks, it works. I'm trying to mouse over in the screen and be able to click on any part and show a rounding box on the clicked element and I wonder if it's possible that in case I click on a link like a button or a tag, prevent such action. – Jose Antonio Mateos Jan 02 '18 at 19:24
  • Also, once i get a nodeAtPoint, how can i set/get attributes? I do not find how to pass a DOMNodeAtPoint object to DOMElement to able to iterate over attributes. – Jose Antonio Mateos Jan 02 '18 at 19:43
  • browserView.MouseDown doesn't work anymore, can you update this example? – Capt. Rochefort Jun 18 '18 at 17:27