0

I am using C# winforms and have a panel that scrolls that I would like to detect the coordinates of a mouse click within the panel in relation to the panel.

I am simply trying to get the coordinates and print them out for now. There is already another post about this on here but it's not letting me ask this question there so I thought I'd post another

The first line is run in another function and the function the line is adding is below that. I am getting errors that e.y and e.x are not defined. Any suggestions would be greatly appreciated.

MapPanel.Click += new System.EventHandler(OnMapClick); 


void OnMapClick(object sender, EventArgs e)
{
    Point scrolledPoint = new Point(e.X - MapPanel.AutoScrollPosition.X,
                                    e.Y- MapPanel.AutoScrollPosition.Y);
    Console.WriteLine(scrolledPoint.ToString());
}
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
N.Dance
  • 11
  • 3
  • TaW's answer [here](https://stackoverflow.com/questions/45072620/get-position-of-cursor-on-panel-with-scrollbars) is correct. Your `Control.Click` handler is not. Change it to `void OnMapClick(object sender, MouseEventArgs e)` (`MouseEventArgs` instead of `EventArgs`). You should use the `MouseDown` event, it's more appropriate here. – Jimi Oct 18 '19 at 05:25
  • yes it is as I could not ask on that thread as i don't have high enough rating as I am fairly new to this site. thankyou for the response. Complelty missed that thankyou :) – N.Dance Oct 18 '19 at 08:20
  • Yes it is. As mentioned above my reputation is too low due to not using stack overflow much and it wouldn't let me ask the question there, I did try to buy got error your rep needs to be over 50 – N.Dance Oct 18 '19 at 09:38

0 Answers0