Mouse coordinate

  • Thread starter Thread starter MAY
  • Start date Start date
M

MAY

hi,

How to get the current mouse position on the screen??
I tried Control.MousePosition.X and Control.MousePosition.Y but fail.

Thanks!

MAY
 
Thx for reply :)

If there have form and a button on it, i want the button move with mouse
cursor when mouse down, and the button stop moving when mouse up. How can i
do that?

thx a lots.

MAY
 
What you're trying to do is basically a design-time editor.

Override the OnMouseDown method on the Form and based on the X & Y
co-ordinates that come, find out if you hit the button. If you hit the
button, set a boolean flag and keep a local copy of the X & Y co-ordinates.

Now, override the OnMouseMove method. Check if the boolean flag is set. If
set, get the current X & Y co-ordinates and compute the delta between the
old and new co-ordinates. Now, you can move the button delta distance.

Over-ride the OnMouseUp method. Reset the flag.

HTH

-vJ
 
Hi Vijaye Raji,

Thanks for valuable reply. My problem now is how to make the button move
with mouse cursor. Is that in the OnMouseMove:

lastPoint=curPoint;
curPoint=new Point(e.X , e.Y );
if(this.drag)
{
Point pts=new Point(Control.MousePosition.X+ (lastPoint.X -curPoint.X ),
Control.MousePosition.Y+ (lastPoint.Y -curPoint.Y ) );
this.LocationSensor=pts;
}


MAY
 
Back
Top