I have a control that scrolls vertically. I need to calculate the mouse position (on click) relative to the top of the control, not just the visible area.
For example, say my control has height of 500. The scroll bar cause the visible rectangle to have height of 100. So when I am partially scrolled, the client coordinate (from mouse click) will return a number relative to the client rectangle (50, for example).
But what I want to know is the offset from the start of my control, so it would be something like 250.
I've been trying for a while to figure this out, and I think I must be overlooking something easy because I'm not finding much info on the topic.
Thanks.
Try looking at the PointToClient Method and the MousePosition Method and try taking the ScreenCoordinates of the mouse and converting it to the relative coordinates of your control.
Point screenPos = new Point(MousePosition.X, MousePosition.Y);
Point myPos = myControl.PointToClient(screenPos);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With