-
October 23rd, 2009, 12:58 AM
#1
Change the mouse cursor location dynamically
Hi,
I want to restrict the mouse cursor movement only on Grid points. Grid Point may be float or int value. I have tried in the way i have added in code block, but even for int value it is not working. Is there any way to change mouse cursor dynamically to int or float values.
for eg;
The mouse should move in 2.5 multiples. It can be like points specified below
100,50 102.5,50
100,52.5 102.5,52.5
I have try to implement it like this
Code:
if (!this.Cursor.Equals(Cursors.Default))
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(CalValue.X, CalValue.X); // CalValue can be of Int or Float
Cursor.Clip = new Rectangle(this.Location, this.Size);
}
Thanks
-
October 23rd, 2009, 01:11 AM
#2
Re: Change the mouse cursor location dynamically
Originally Posted by hotsaravana
Code:
if (!this.Cursor.Equals(Cursors.Default))
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(CalValue.X, CalValue.X); // CalValue can be of Int or Float
Cursor.Clip = new Rectangle(this.Location, this.Size);
}
why are you passing only X values in both the paramaters ?
-
October 23rd, 2009, 01:30 AM
#3
Re: Change the mouse cursor location dynamically
Originally Posted by vcdebugger
why are you passing only X values in both the paramaters ?
Sorry I have posted wrongly...
if (!this.Cursor.Equals(Cursors.Default))
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(CalcValue.X , CalcValue.Y); // CalcValue can be float or int
Cursor.Clip = new Rectangle(this.Location, this.Size);
}
When CalcValue is in float I want Cursor.Position value to be in float. But cursor.Position does not accept float value.
Is there any other way to do so?
-
October 23rd, 2009, 06:31 AM
#4
Re: Change the mouse cursor location dynamically
There are no half pixels. That is why points are integer values. You need to round the values to the integer value you want, then set the cursor position
-
October 23rd, 2009, 07:47 AM
#5
Re: Change the mouse cursor location dynamically
Originally Posted by sotoasty
There are no half pixels. That is why points are integer values. You need to round the values to the integer value you want, then set the cursor position
My Graphics unit is in millimeter, Not in Pixel.Whether it is possible to set float value to cursor position.
-
October 23rd, 2009, 10:09 AM
#6
Re: Change the mouse cursor location dynamically
Code:
Cursor.Position = new Point(CalcValue.X , CalcValue.Y); // CalcValue can be float or int
Points are in integers. You can not use a float value.
-
October 26th, 2009, 05:35 AM
#7
Re: Change the mouse cursor location dynamically
Originally Posted by hotsaravana
My Graphics unit is in millimeter, Not in Pixel.Whether it is possible to set float value to cursor position.
try to map the small millimeter units to pixels because thats the smallest level possible.
-
October 26th, 2009, 08:39 AM
#8
Re: Change the mouse cursor location dynamically
If you want to constrain cursor movement to whatever location, you could use the SetCapture ReleaseCapture ClipCursor APIs, or the Cursor.Clip property to constrain your cursor to any place.
-
October 27th, 2009, 01:23 AM
#9
Re: Change the mouse cursor location dynamically
Originally Posted by HanneSThEGreaT
If you want to constrain cursor movement to whatever location, you could use the SetCapture ReleaseCapture ClipCursor APIs, or the Cursor.Clip property to constrain your cursor to any place.
Code:
protected override void OnMouseMove(MouseEventArgs e)
{
PointF[] MouseMove = new PointF[1];
MouseMove[0].X = e.X;
MouseMove[0].Y = e.Y;
Graphics g = this.CreateGraphics();
g.PageUnit = GraphicsUnit.Millimeter;
g.TransformPoints(CoordinateSpace.Device, CoordinateSpace.Page, MouseMove);
MouseMove[0].X = MouseMove[0].X / 2.5f;
MouseMove[0].Y = MouseMove[0].Y / 2.5f;
Point truncatePt = Point.Truncate(MouseMove[0]);
MouseMove[0].X = truncatePt.X * 2.5f;
MouseMove[0].Y = truncatePt.Y * 2.5f;
this.Cursor = new Cursor(Cursor.Current.Handle);
//Convert Milleter to Pixel
Point pp = new Point((int)(MouseMove[0].X * g.DpiX / 25.4f), (int)(MouseMove[0].Y * g.DpiY / 25.4f));
Cursor.Position = pp;
Cursor.Clip = new Rectangle(this.Location, this.Size);
base.OnMouseMove(e);
}
I have tried as above. But the control is not moving to the child form , it switch in the parent form.
Whether it is possible to change cursor on Mouse move using SetCapture, ReleaseCapture and ClipCursor APIs, if so please provide a sample code.....
Thank You
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|