孟子老兄BLOG的彩色光标 C#WINFORM

首先引用: 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;
  }

转载于:https://www.cnblogs.com/lkcn/archive/2004/10/25/56450.html

你可能感兴趣的:(孟子老兄BLOG的彩色光标 C#WINFORM)