Form off Screen - Cursor off Form Area - c#

Following this post
I've thought a "simple" solution.
My goal is to prevent mouse movement when my winForm has reached the allowed coordinates.
For instance, if offScreen is for maxX (right border), user will can move mouse in all direction except for left to right.
Is there some event (native too) to accomplish that?

Related

C# WPF toggle button drag, swipe right-left

I want to make a custom button. It's like toggle but has 3 functions. As seen in the first picture, the "PICK" circle button appears in the middle. When I swipe the circle to the right or left, it should move towards the direction I swiped and hold until the end. How can I do that?
Thanks.

Drag map with limits

I have a map (2d) which is about 5 times the size of the screen area. I can touch drag the map. However the user must only be able to drag it as far as the map is still showing. So the empty area outside map isn't showing.
So my question is: which of the two methods are best:
1) have colliders at the side of the screen and then put colliders on each side of the map. Then checking for collision and if so move the map so its collider does not touch the screen collider.
Or
2) check for the position of the map (i have an adjustable screen size according to device) and then stop the drag if it gets dragged further than visibility of screen. Using coordinates and math.
Will it take up more space (the ios/android) file if I use solution 1?
Thanks.

Monogame/C# - Mouse position flickering

I am having some problem with mouse position in MonoGame and I can't really figure out what I am doing wrong. I want the game window to be at the position of my cursor, so I made this simple line:
protected override void Update(GameTime gameTime)
{
Window.Position = new Point(Mouse.GetState().X, Mouse.GetState().Y);
base.Update(gameTime);
}
But if I do this, the game window flickers between two positions. What is the problem ? Am I doing something wrong ?
Thank you!
Well it actually makes sense when you think about it. Let me make an example:
Cursor is 500,500 (in relation to Window)
Window is 300,300 (in relation to Screen)
The first time the code runs, it moves the window to 500,500.
Meaning the cursor will now have a location of 300,300 (in relation to Window).
The second time the code runs, it will detect the mouse is now at 300,300, and thus move the Window back to 300,300.
As such it runs forever.
To accomplish what I think you want, you'd need to account for the current position of the Window.
Which means you'll have to "lock" the position of the mouse (in relation to the Window), and whenever this changes, move the Window the amount that the mouse position moved. And of course move the mouse back again

Zoom a custom user control on mouse move event

I am trying to zoom a custom usercontrol which contains a polygon, say paralellogram, which I created with the help of four points with X,Y coordinate but, when I try to zoom it on mouse move event, it stays at the same position and doesn't work out. Any suggestions ?

Suppress mouse-movement

I need to freeze the windows mouse cursor on the screen, so it stays hovered over a specific UI element. While the mouse is in this frozen state, I would still like to be able to interact with the UI using a "fake" mouse pointer.
Currently, I've got a low level mouse hook that prevents WM_MOUSEMOVE messages from being passed along, effectively stopping all real mouse movement. However, when I don't pass along the updated coordinates, windows actually sends me the old coordinates in a separate WM_MOUSEMOVE message, as if to correct for the fact that the mouse didn't move.
Any idea on either how to prevent Windows from sending me these corrected coordinates, or another approach of how I can freeze the actual mouse curosr and still allow the physical mouse to control a "Fake" cursor?
You can suppress mouse cursor movement by using DirectInput exclusive mode.
You should acquire mouse input device when cursor movement must be suppressed. This will block windows cursor movement but you can get messages for your fake cursor using DirectInput API.
If you move the mouse cursor position in response to a WM_MOUSEMOVE message, to put the mouse back to where you want it, you will get another mouse move message because the mouse has been moved again (because you moved it). To stop this, don't set the mouse position if it is already in the right place.
You may also want to clip the mouse position to your window and get exclusive access to it.
Why don't you just draw an image of the cursor at the place you want it frozen, then set the real mouse cursor to be hidden (Cursor.Hide IIRC).
It's not clear to me what you are trying to do, perhaps making a tutorial for your app and you want to show mouse movements, etc. Perhaps this library will be useful:
http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx

Categories

Resources