Solve C to get the mouse relative to the current window coordinates of the implementation method

  • 2020-05-12 03:03:38
  • OfStack

The current position of the mouse is often used when writing client applications. In C#winform, you can use Control.MousePosition to get the coordinates of the current mouse, and PointToClient to calculate the coordinates of the mouse relative to a control, as shown below
Point screenPoint = Control. MousePosition; // coordinates of the mouse relative to the upper left corner of the screen
Point formPoint = this. PointToClient (Control. MousePosition); // coordinates of the mouse relative to the upper-left corner of the form
Point contextMenuPoint = contextMenuStrip1. PointToClient (Control. MousePosition); // coordinates of the mouse relative to the upper left corner of contextMenuStrip1


Related articles: