c# - Unexpected output from checking if mouse within control -
i implementing custom drag , drop interface winform buttons , after viewing several solutions on how obtain mouse position , check against control bound have not been able work.
i have tried:
button.clientrectangle.contains(pointtoclient(cursor.position))
and
button.clientrectangle.contains(pointtoclient(control.mouseposition))
both of these have failed work. checking mouse bounds seem simple operation, stumped.
my speculation of unexpected values are:
- process of obtaining cursor position may in wrong corner of cursor image
- method/function not work on buttons reason
you using wrong object reference, calculating mouse position relative form instead of button. , writing in way make hard debug. fix:
var pos = button.pointtoclient(cursor.position); system.diagnostics.debug.writeline(pos); // easy if (button.clientrectangle.contains(pos)) { // etc... }
Comments
Post a Comment