A
A
Avery0072014-03-04 15:10:55
C++ / C#
Avery007, 2014-03-04 15:10:55

How to get cursor coordinates when clicking relative to control's local coordinates?

There is a class inherited from ScrollableControl. When you click inside it, you need to find out the coordinates of the cursor relative to local coordinates (the coordinate system starts from the upper left corner), taking into account the scroll.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aush, 2014-03-04
@Avery007

public class MyScrollableControl : ScrollableControl
    {
        protected override void OnMouseClick(MouseEventArgs e)
        {
            var local = new Point(e.X - AutoScrollPosition.X,
                                  e.Y - AutoScrollPosition.Y);
            base.OnMouseClick(e);
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question