it is possible to change global mouse cursor from c#? the thing is i use a global hook shortcut key to capture a window like spywindow and i want to change mouse cursor globally when i select my handle and restore it when i click left mouse. Another question is about the click itself. When I'm in capture mode can i take click just for my purpose?it will be nice if i didn't press stuff on screen when i select my window!. Thanks!
Use
this.Cursor = Cursors.Cross; //to change the cursor to a cross, see Cursors for more options
when you select your handle, and when the left button is clicked use,
this.Cursor = Cursors.Default;
this should just be the relevant form/object that you want to change the cursor for.
For the cursor position, if you're using windows forms, just use System.Windows.Forms.Cursor.Position, as it is settable. The cursor class, not the cursor property of your form. To get global (screen) coords just use Form.PointToScreen(Point p). There's also PointToClient for the reverse.
Related
My UWP application contains a map with several POI. I am trying to change the mouse cursor from an arrow to a hand when hovering over specific poi to indicate its clickable.
This would change the cursor as soon as it enters the map still, as a simple test, I added a PointerEntered event for the mapcontrol and within it I have the following to change the cursor:
Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 0);
It appears though the cursor does change however immediately gets overridden back to the pointer cursor.
Edit: Just realised When a poi is clicked (i.e. is selected) the cursor changes to a hand even when not over the map control until the poi is unselected. No good as I would like the cursor to change dynamically when hovering over a poi and revert back to cursor when moved away.
Change pointer cursor when hovering over map elements
I'm afraid you can't edit the default cursor for map element, Because it has handled internally, it will not fired, even you has listen PointerEntered event, it consumed by the control and not passed up the control chain. If you do want this feature, the better way is post this feature with windows feed backhub app.
I don't know if it works just like WinForms, I had to do something like this to click on labels (couldn't use link-labels), what I used was in the Mouse_Move event of the label and it was basically
if (Cursor.Current == Cursors.Default)
{
Cursor.Current = Cursors.Hand;
}
and similar changes and behaviors due to the various conditions. This however got me a small issue: this statement changes the mouse graphic anytime you move on the control, but personally on Windows settings I use the trail graphic function for the mouse (leaving a trail of pointers whenever I move the mouse on the screen), what I suggested you disables this function, or better, it conceals it, since it "recreates" the mouse graphic for every move you do onto the control, and thus it "undoes" the graphic for the mouse and recreates it as a Hand (in my instance). If it doesn't concern you though, it works just fine.
Just I repeat myself: I use this on WinForms, but since it's C# I suppose it just will work(?)
I have created a custom control.
I have drawn a text inside the control.
In that, I'm trying to change the default cursor to Hand cursor when moving the mouse pointer on a particular region(Region where the text drawn inside the control).
For that, I have changed the cursor on the MouseMove event of the control.
if (textRect.Contains(e.Location))
{
Cursor.Current = Cursors.Hand;
}
I'm getting a flickering effect when moving the mouse over the control.
That is, the cursor is changed to hand cursor and back to default cursor.
I can't able to figure out why it is happening.
Provide your valuable suggestions to resolve this.
Thanks in advance.
I want to create another mouse cursor that can move and click automatically in one window, and main mouse cursor can move in and out but can't change anything in this window.
Can C# do this? How can I do it?
Thanks
I'm trying to display a context menu where the user clicks the mouse in a WPF application. I've handled the OpenContextMenu event and the handler has a pair of doubles, e.CursorLeft and e.CursorTop which are the coordinates of the mouse click relative to the control that was clicked (in this case a DataGridCell). If I display the context menu using those coordinates it appears relative to the application window offset by the cursor amounts.
How can I convert those DataGridCell-relative Cursor coordinates into window coordinate space?
You can use the UIElement.TranslatePoint(Point, Visual) method to convert coordinates from one control's coordinate space to another. The following code should do what you want (not tested!):
Point target =
myDataGridCell.TranslatePoint(new Point(e.CursorLeft, e.CursorTop), Application.Current.MainWindow);
However, if you only want to display a context menu, you could also simply assign the FrameworkElement.ContextMenu property for the control which should show the context menu. This way, the position will be positioned at the mouse cursor automatically. If you have a more complicated scenario, you might still use the method above.
I saw the Cursor File in the dialog box when adding a new item. Actually what it will do and what is the use of it ?...Thanks..
It contains the Image(s) to draw a Cursor (mousepointer) on your screen.
From MSDN:
A cursor is a small picture whose
location on the screen is controlled
by a pointing device, such as a mouse,
pen, or trackball. When the user moves
the pointing device, the operating
system moves the cursor accordingly.
You can use Visual Studio to create Cursor Files (.cur) which can then be loaded using the Windows Forms Cursor class or Win32 API calls such as LoadImage.
Start a new project from the Windows Forms Application template. Project + Add New Item, select Cursor File. Draw something. Project + Properties, Resources tab. Drag and drop the cursor onto the resource window so a resource is added. Make your form constructor look like this:
public Form1() {
InitializeComponent();
this.Cursor = new Cursor(new System.IO.MemoryStream(Properties.Resources.Cursor1));
}
Press F5 and have a look-see at your new mouse cursor.
If you want to change the cursor when it hovers above an object on your user interface and you are not satisfied with the builtin cursor you can create a custom cursor. Custorm cursors is like a small image, but has some extra properties:
Transparency mask so the cursor can have a shape that is not rectangular.
Hotspot location used to determine the mouse coordinates when the cursor is moved. Some cursors have the hotspot in the upper left corner (e.g. the arrow) while other have in the middle (e.g. the cross-hair) etc.