Skip to content

Instantly share code, notes, and snippets.

@smoothdeveloper
Created November 4, 2014 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoothdeveloper/9357bfb8260dea1cf2a0 to your computer and use it in GitHub Desktop.
Save smoothdeveloper/9357bfb8260dea1cf2a0 to your computer and use it in GitHub Desktop.
Winforms / Cursor position in control
static Point Negate(this Point point)
{
return new Point(-point.X, -point.Y);
}
static Point CursorPositionWithinControl(this Control control)
{
var cursorPosition = Cursor.Position;
var offset = control.PointToScreen(Point.Empty);
cursorPosition.Offset(offset.Negate());
return cursorPosition;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment