We need a lot of custom cursors in our software to make the necessary prompts in the user interaction process. We started by putting the cursor in a resource file and then loading it with code like this:
var cursor = new cursor (new MemoryStream (Resource.openhandicon));
... ...
if (usedefaultcursor)
{control
. Cursor = Cursors.Default;
}
else
{control
. Cursor = Cursor;
}
However, when a custom cursor should be displayed during the test, it is always replaced with success and sometimes unsuccessful.
It turns out to be. NET, the cursor constructor cannot load a cursor outside the Black-and-white color of the cursor class. However, you can bypass this restriction by following the code:
public static Cursor Loadresourcecursor (byte[] data
{
var path = Path.gettempfilename ();
File.writeallbytes (path, data);
return new Cursor (Loadcursorfromfile (path));
}
[System.Runtime.InteropServices.DllImport ("User32.dll")]
private static extern IntPtr Loadcursorfromfile (string fileName);
All cursors can be used normally after this process.
Source: http://www.cnblogs.com/brucebi/archive/2013/04/02/2995888.html