This article from: http://www.cnblogs.com/hzbzxm/archive/2008/09/15/1291104.html
I have tried to customize the mouse style in winform before, and the mouse displayed in the result turns into a monochrome.
Later, Baidu used APIs.
First, two namespaces are introduced.
Using system. runtime. interopservices;
Using system. reflection;
Import API
[Dllimport ("user32.dll")]
Public static extern intptr loadcursorfromfile (string filename );
[Dllimport ("user32.dll")]
Public static extern intptr setcursor (intptr cursorhandle );
[Dllimport ("user32.dll")]
Public static extern uint destroycursor (intptr cursorhandle );
Next, use your mouse style.
Private void form1_load (Object sender, eventargs E)
{
Cursor mycursor = new cursor (cursor. Current. Handle );
Intptr colorcursorhandle = loadcursorfromfile ("My. cur"); // Mouse icon path
Mycursor. GetType (). invokemember ("handle", bindingflags. Public |
Bindingflags. nonpublic | bindingflags. instance |
Bindingflags. setfield, null, mycursor,
New object [] {colorcursorhandle });
This. cursor = mycursor;
}
Now we will introduce another method that does not use APIs. The mouse style only requires a transparent background image, in PNG or GIF format.
Write Method
Public void setcursor (Bitmap cursor, point Hotpoint)
{
Int hotx = Hotpoint. X;
Int hoty = Hotpoint. Y;
Bitmap mynewcursor = new Bitmap (cursor. Width * 2-hotx, cursor. Height * 2-hoty );
Graphics G = graphics. fromimage (mynewcursor );
G. Clear (color. fromargb (0, 0, 0, 0 ));
G. drawimage (cursor, cursor. Width-hotx, cursor. Height-hoty, cursor. Width,
Cursor. Height );
This. cursor = new cursor (mynewcursor. gethicon ());
G. Dispose ();
Mynewcursor. Dispose ();
}
Use this method in the event you want to change the mouse style.
Private void form1_load (Object sender, eventargs E)
{
Bitmap A = (Bitmap) bitmap. fromfile ("mycur.png ");
Setcursor (A, new point (0, 0 ));
}