Question:
Tell me how to change the cursor to your own? I do this:
Cursor cur = new Cursor(new System.IO.MemoryStream(global::MSU.Properties.Resources.cursorDragDrop));
Writes an error –
Most appropriate overloaded method for "System.IO.MemoryStream.MemoryStream (int)" has multiple invalid arguments
Answer:
For example, you can do this (from the available cursors):
Cursor.Current = Cursors.WaitCursor;
Or your cursor like this:
Cursor.Current = new Cursor("C:\\<путь к файлу>\\icon.cur");
By the way, pay attention to the .cur
file .cur
, for example .gif
cannot be packaged there. VisualStudio
has the ability to create Cursor File
(at least it was). All you need is to specify the path to the file and, in fact, the file itself. It will be useful: Cursors – properties
If you want to sew it into the program, then I think it's worth adding a cursor file ( .cur
) to the project resources. Then, in code, get that file, convert and create a cursor, something like this:
var img = new Bitmap(WindowsFormsApplication1.Properties.Resources.myCursor);
Icon icon = Icon.FromHandle(img.GetHicon());
Cursor cur = new Cursor(icon.Handle);
Cursor.Current = cur;
This code is given as an alternative example, but it has its drawbacks in the form of leaking native resources. Also, if you click with the mouse in the window of someone else's program, a problem may arise. Therefore, I advise you to read this answer Change Cursor HotSpot in WinForms .NET , it will be more correct using WinAPI
.