Problem
When the mouse cursor interacts with the application, the mouse cursor should be hidden. The problem is: I don't know how.
Question
How can I hide the mouse cursor when the mouse cursor interacts with the application?
You can subscribe for to something like Window.Activated event or similar one to know when user is interacting with the window. And call
Cursor.Hide();
to hide the cursor. Or
Cursor.Show();
to display it
Related
(NET Compact Framework 3.5, Windows CE 6.0)
I want to hide mouse cursor.
So, I use Curosr.Hide()
I have two forms, Form1, Form2.
The size of Form2 is smaller than Form1.
PictureBox1 is in Form1.
When PictureBox1 is clicked, Form2 will be opened. (modal)
At this point, the mouse cursor suddenly appears outside area of Form2.
MouseDonw PictureBox1 -> Form2.ShowDialog -> Show MouseCursor
I have never done Cursor.Show()
Why does the mouse cursor appear?
Added the following
I moved Form2.ShowDialog() from 'MouseDown Event' to 'MouseUp Event'. then it is resolved. Why?
First, form show and other 'actions' usually are done with a mouse click event. That is fired after mouse down and mouse up.
If you break the normal sequence, ie show a form on a mouse down event, the GUI is in 'Mouse down/move' mode, for example to drag an element or draw a line.
As each element can show/hide the mouse cursor, the Windowing System recognizes youre Cursor Hide on the second form, but the first form still shows the mouse cursor as the Mouse Up event is not done.
If you would like to know more about the Basics, you should look at a native WndProc and how are Window Messages are handled. Programming Windows by Charles Petzold is still the bible for Windows programming.
I have a Windows 8 application, and I need to detect when the mouse is at the bottom of the screen because my application has a CommandBar, and I would like to open it when the mouse is at the bottom. I already have swipe gestures that will open it when the user swipes, but now I have an added requirement for when the user does not have a touch device and instead must bring the mouse to the bottom of the screen to show my CommandBar. I am used to WPF's style of MouseMoved events, but unfortunately these are not available in Metro applications, so how can I get the mouse position or at least detect that the user has brought the mouse to the bottom of the screen? I have tried searching about this, but I couldn't find anything...perhaps I am missing something?
As Chue X said the standard way to open the app bar by mouse is right click.
Windows Runtime apps use Pointer messages for all pointer input: Mouse, touch and pen will all generate PointerPressed, PointerMoved, etc. You can examine the Pointer event args to see which type of input it is in the PointerPoint.PointerDevice.PointerDeviceType.
There are slightly different versions of the Pointer events on the CoreWindow (with full window scope) and on the xaml UIElement (scoped to the element). You can use either in a xaml app. For your use either would work. They give essentially the same information.
Responding to mouse interactions (XAML) http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994936.aspx
Here's the code I used to achieve this behavior from any OnPointerMoved event handler:
... OnPointerMoved(PointerRoutedEventArgs e)
{
PointerPoint point = e.GetCurrentPoint(page);
if (point.Position.Y > page.RenderSize.Height - 5)
{
page.MainMenu.IsOpen = true;
}
}
I have a small video app that i would like to give vlc-like functionality. By that, I mean having a certain element disappear and appear on mouse move or mouse not moving. I have a rough concept of how to do this but I have no ideea how i coul detect if the mouse is moving or not. I thought about using the GetPosition function but that will just give me the mouse's position and won't let me know if the cursor is moving or not. I would like to use a timer to count down 2-3 seconds after the mouse has stopped moving and then either fade out the control or just make it collapse without further ado. I can't check the value of the position variable every milisecond. Is there some other way to do this ?
You can use a hook functionality so you will be notified when a mouse move, I use to use this free opensource library.
How to use it:
using Gma.UserActivityMonitor.GlobalEventProvider;
GlobalEventProvider _globalEventProvider1
= new Gma.UserActivityMonitor.GlobalEventProvider();
this.globalEventProvider1.MouseMove += HookMouseMove;//to listen to mouse move
Capture the mouse. Release the capture if the user actually clicks anywhere else. Then you can use the standard WPF mouse move event.
myElement.MouseMove += (my MouseMove handler)
Mouse.Capture(myElement);
I've created a form that's maximized over the entire screen.
Within that form, and sized to fill the entire form, I've placed a panel with background color set to Red. The form's TransparencyKey is set to Red.
Therefore, the Panel is like a "keyhole" - you can see the desktop that's directly underneath it.
When the user clicks on the panel, OR, presses a key on the keyboard, I want to take action.
But, because the panel is completely transparent, when it is clicked or a key is pressed, nothing happens. If I make the panel non-transparent (setting it's background color to Blue, for example), it does respond to clicks.
What's the best way to get the panel to respond to clicks and keypresses?
Do I have to hook all mouse an keyboard events on the entire system or is there a simpler way?
The panel does not take in text input, you can set your main form to handle the keypress event.
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.form_KeyPress);
http://screensnapr.com/v/VovWAi.png
As for getting the mouse location on your panel, you can use the mouseclick event
this.panel1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseClick);
http://screensnapr.com/v/DB3kCQ.png
I have tested it, and it works on a fullsize transparent panel
I've discovered that I can use GetAsyncKeyState to respond to both keypresses and mouse clicks.
[DllImport("user32.dll")]
public static extern int GetAsyncKeyState(System.Windows.Forms.Keys vKey);
Then, I can call GetAsyncKeyState(Keys.LButton) and GetAsyncKeyState(Keys.Escape), for example. Much simpler than hooking all keyboard and mouse events.
I have an application wich open a modal form with the ShowDialog method.
Once this form is displayed I want to capture the mouse movement even if the cursor is outside the form.
How can I capture the mouse movement? I saw something with the Capture property but I cannot manage to make it work.
[edit]
I want to be notified if the mouse move outside the form.
The Capture property is the correct way, but there are some limitations.
Only the foreground window can capture the mouse
Mouse capturing can be disabled by other parts of the system
The Win32 API function SetCapture gets reset everytime a "mouse up" event occours. I assume that also applies for .NET.
See the remarks section of Capture property.
When the mouse is captured, you'll receive the usual events but with a wider mouse coordinate range (for example a negative X position, if the mouse is left of the capturing control)
Mouse capturing is fragile, because of it's global nature. Check if there are other ways to handle certain events. Perhaps the MouseLeave or MouseEnter events are enough in your case.
You can just use the static property Control.MousePosition.
You can read the position of the cursor, using the Cursor.Position property, see Cursor.Position