How to change the standard cursor on your own? For example, I put a file into resources:

MySOrce.cur is the cursor itself.

I used many methods, but I can’t use it from resources at all!

In the resource itself, the file is named without .cur That is, just the name MySOrce

Used this method:

Class:

class NewCursorAPI { public static Cursor LoadCustomCursor(string path) { IntPtr hCurs = LoadCursorFromFile(path); if (hCurs == IntPtr.Zero) throw new Win32Exception(); var curs = new Cursor(hCurs); // Note: force the cursor to own the handle so it gets released properly var fi = typeof(Cursor).GetField("ownHandle", BindingFlags.NonPublic | BindingFlags.Instance); fi.SetValue(curs, true); return curs; } [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern IntPtr LoadCursorFromFile(string path); } 

Then use:

  public FormLoader() { InitializeComponent(); this.Cursor = NewCursorAPI.LoadCustomCursor(@"c:\windows\cursors\aero_busy.ani"); } 

But the cursor appears only if the file itself is located somewhere in the folder on the computer itself, and you need to make it run from resources!

    1 answer 1

    Found something similar here

     [DllImport("User32.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] private static extern IntPtr LoadCursorFromFile(String str); public static Cursor LoadCursorFromResource(string resourceName) { Stream cursorStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); // Write a temp file here with the data in cursorStream Cursor result = new Cursor(LoadCursorFromFile(tempFile)); File.Delete(tempFile); return result. } 

    The trick is that you unload the cursor from the resources into the tempo directory, and then after loading you delete the file.

    And to replace the cursor you need to do this:

     Cursors.Current = LoadCursorFromResource("My.Namespace.Filename"); 
    • @ArteS, of the type proposed to implement this upload yourself. You can at least make it in the program folder. - iluxa1810 2:44