服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

.net中实现彩色光标,动画和自定义光标


  下面是完整的例子,可以通过命令行编译即可看到效果。
  
  test.cs
  
  using system;
  using system.drawing;
  using system.windows.forms;
  using system.runtime.interopservices;
  using system.reflection;
  
  namespace colorcursor
  {
   /// <summary>
   /// 本例子的作用:
   /// 在.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 = "欢迎光临【孟宪会之精彩世界】:http://dotnet.aspx.cc/";
   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;
   }
   }
  }

扫描关注微信公众号