当前位置: 移动技术网 > IT编程>开发语言>c# > .NET中实现彩色光标、动画光标及自定义光标的方法

.NET中实现彩色光标、动画光标及自定义光标的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文所述实例主要完成dotnet中实现彩色光标、动画光标及自定义光标的功能。以下是完整的程序实例,可以通过命令行编译可看到运行效果。

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 = "欢迎光临【移动技术网】://www.jb51.net/";
 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;
 }
 }
}

相信本文所述实例对大家的c#程序设计能够起到一定的帮助作用。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网