In this example, the color cursor, animation cursor, and custom cursor are implemented in. NET. The following is a complete example. The effect can be seen through command line compilation.
Test. cs
Using System;
Using System. Drawing;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Using System. Reflection;
Namespace ColorCursor
{
/// <Summary>
/// Functions of this example:
/// Color cursor, animated cursor, and custom cursor are implemented in. NET.
/// </Summary>
Public class Form1: System. Windows. Forms. Form
{
[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 );
[STAThread]
Static void Main ()
{
Application. Run (new Form1 ());
}
Public Form1 ()
{
This. Text = "Welcome to [Meng xianhui wonderful world]: http://dotnet.aspx.cc /";
Cursor myCursor = new Cursor (Cursor. Current. Handle );
// Din1_u2.ani is the cursor that comes with windows:
IntPtr colorCursorHandle = LoadCursorFromFile (@ "C: WINNTCursorsdinosau2.ani ");
MyCursor. GetType (). InvokeMember ("handle", BindingFlags. Public |
BindingFlags. NonPublic | BindingFlags. Instance |
BindingFlags. SetField, null, myCursor,
New object [] {colorCursorHandle });
This. Cursor = myCursor;
}
}
}