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:

  1. process of obtaining cursor position may in wrong corner of cursor image
  2. 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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -