首先引用:using System.Runtime .InteropServices;
using System.Reflection ;
引入:
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 );
}
实现:
private void Form1_Load(object sender, System.EventArgs e)
{
Cursor myCursor = new Cursor(Cursor.Current.Handle);
//dinosau2.ani为windows自带的光标:
IntPtr colorCursorHandle = LoadCursorFromFile(@"C:\WINNT\Cursors\dinosau2.ani" );
myCursor.GetType().InvokeMember("handle",BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.SetField,null,myCursor,
new object [] { colorCursorHandle } );
this.Cursor = myCursor;
}
using System.Reflection ;
引入:
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 );
}
实现:
private void Form1_Load(object sender, System.EventArgs e)
{
Cursor myCursor = new Cursor(Cursor.Current.Handle);
//dinosau2.ani为windows自带的光标:
IntPtr colorCursorHandle = LoadCursorFromFile(@"C:\WINNT\Cursors\dinosau2.ani" );
myCursor.GetType().InvokeMember("handle",BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.SetField,null,myCursor,
new object [] { colorCursorHandle } );
this.Cursor = myCursor;
}