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.
Related
I want to reposition a uwp app everytime it opens, to bottom left just above the taskbar, to mimic start menu like behavior.
I have tried using AppWindow class to create secondary views and resize and reposition them with the build in methods, but the problem is there is no appwindow instance for the main window.
AppWindow = await AppWindow.TryCreateAsync();
AppWindow.RequestMoveRelativeToDisplayRegion(displayRegion, new Point(xpos, ypos));
AppWindow.RequestSize(new Size(wWidth, wHeight));
In case of ApplicationView for the main window only resizing method is available.
var view = ApplicationView.GetForCurrentView();
view.TryResizeView(new Size(wWidth, wHeight));
So technically I need to do calculations based on display region (monitor) and then place the app on bottom left and also resize it to a specific size depending on monitor effective pixels, resizing isnt the problem as their is a method for it, but moving and repositioning the app window to a specific place on the screen is a problem as there is no method for it.
Thanks.
moving and repositioning the app window to a specific place on the screen is a problem as there is no method for it.
Yes, UWP doesn't have the API that could change its position in the system as mentioned here:UWP Window Placement and How to set UWP app position (x & y coordinates) . Although this is an old question, the answer doesn't change. The position of the UWP window can't be controlled from the app level.
I want to be able to drag around a 100% zoomed picture in a picturebox: http://spunit.tk/x/dragpic1.png.
I want it to work exactly like the Windows Photo Viewer: http://spunit.tk/x/dragpic2.png.
How is this possible?
I believe you need to maintain the coordinates of that picturebox, also set its view style to full-image, without any stretching.
Then, you will need three mouse events: mouse down, mouse up and mouse move, where you can get the mouse coordinates and capture or release mouse to translate the picture box according to mouse delta translation.
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 want measuring tool in project that will be same as measure it in Firefox (add-on). How to do this?
To get such a think to work you'll need an application that runs as a tray icon or something like that. Then you open your application and tell him, that you'd like to measure.
Now, you'll go and put a transparent window onto the whole screen(s) and wait for a mouse move event. Within the mouse move event, you'll check the mouse button state. If it is going to be hit you know the starting position and you can draw some kind of user-control at this position and if the user releases the mouse button, you're going to stop the resizing of your user-control.
The user-control itself should be semi-transparent and checking for the resizing and/or paint events, to draw the ruler lines around the border.
Last but not least you can show some kind of tooltip or labelcontrol in relation to the position and size of your user-control and screen bounds to give some status informations.
To get a good starting point about how to get the transparent overlay part done, you can take a look into ObjectListView Overlay.
--EDIT--
One solution could be:
Create a separate transparent windows form
Upon certain key press, for instance Ctrl+Shift+R, show your app with lower transparency level; so that user can see the background.
Draw ruler upon form load
You may allow user to move the ruler window with mouse click.
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.