Mouse Movement

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Is there a way I control where a mouse can move?

I.E. i click a button to display a panel that shows more information. I only want the mouse to be able to move within this panel, and not the rest of the form, until the user clicks "Close" button on the panel.

I use to open a seperate form with showdialog() , but I'm trying to cut down on pop up forms and use panels instead...

Thanks,
 
you could just disable everything else on the form except what's ont hat panel instead, that way in your app they can only use what's on the panel instead of your app restricting them from the rest of their computer
 
Only the mouse driver can do this. TouchPad devices from Synaptics have a feature called "Edge Constrain" in the driver, that prevents the mouse from leaving the active window on the first attempt.. you have to "bang" on the window border twice with the cursor, to get it free.. But, as noted, its a driver issue, because the mouse pointer is largely implemented in hardware.

That said, it is possible to programmatically position a mouse cursor, as evidenced by tools such as FakeSurf (intended to defraud AllAdvantage - a pay-while-you-surf scheme) that fake user activity by moving the mouse and clicking on things.. while you cant truly prevent the mouse from leaving the window, you might be able to drag it back in on a timer..
 
I've ended up taking the Panel out of the tabcontrol, and then when the panel is opened, the tabcontrol is disabled, and when the close button is clicked on the panel, the tabcontrol is re-enabled.

I don't like it, but it'll have to do :)

I was hoping there was some kind of constraint you could add to the panel border that didn't allow the mouse to move outside of it if the panel was open
 
What you can do is to detect if mouse moves over other parts of your application, and if so set the cursor position somewhere inside the bounds of your panel. System.Windows.Forms.Cursor.Location is get/set.

I have attached a project that displays this technique. I just used a button to set constraint, and another button inside the panel to remove the constraint. When constraint is set and you try to move mouse outside panel it is placed back inside the panel. You can still move the mouse fast outside the application window to "free" it or use ALT-TAB to another window, this means it doesn't fully lock user out from the rest of the operating system. But it is still ill-behaved, and this should be developed further to play better along with rest of system. For example you can detect if mouse is moving in or out from the contrained form, this to determine if mouse cursor should be re-placed inside panel or outside the form. Also it can be improved to place mouse cursor better near to where it tried to move out of constrained bounds, now I just placed it topleft inside panel.
 

Attachments

  • vbnet20-constrainPanel.zip
    13.8 KB · Views: 22
excellent.

Not too worried about the ALT - TAB, the program runs in Terminal Server and the only things they can do is open the application or log off :)

I have a "close pop-up" link label bottom left, I'll get it so that the mouse cursor moves to there, at least the users should then realise they need to click that to use the form again.

Thanks for the help.
 
Back
Top