Created
November 4, 2014 18:07
-
-
Save smoothdeveloper/9357bfb8260dea1cf2a0 to your computer and use it in GitHub Desktop.
Winforms / Cursor position in control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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