Stop Mouse Cursor from Moving Horizontally, but still want to capture MouseMove Events
In my winforms app, I have a feature that opens a dropdown menu, and you move your cursor left or right to select a sub-option. But, I don't want the cursor to move, I just want the sub-options them selves to move left or right (depending on which direction the mouse is trying to move in). I hope this makes sense to you.
Does anyone know how to stop the cursor from moving in a parti开发者_StackOverflowcular direction, while still being able to capture mousemove events while the user "moves" the mouse?
Any help is appreciated, Thank you!
You should not try to implement this, as it breaks all user interface standards and will just confuse the user. It's not up to your application to decide where the mouse should be able to move. If you want to implement some other way of allowing navigation selection then I would suggest investigating other options.
I don't think you should implement such a solution at all.
But well, you could set the mouse cursor position back to its original position within the MouseMove Handler. But you have to remove the handler before setting back the position and adding them again after this. You can set the Mouse position via pInvoke. How to do that, you can find here http://pinvoke.net/default.aspx/user32.mouse_event
You can set Cursor position manualy
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Cursor.Position = new Point(400,400);
Console.WriteLine("fired");
}
精彩评论