GSpring

生活需要理想,却不能理想化的生活

常用链接

统计

技术链接

移动开发

最新评论

在.NET中实现彩色光标和自定义光标

引自:http://www.pconline.com.cn/pcedu/empolder/net/0410/477929.html
本例子在.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;
  }
  }
  }


posted on 2005-04-15 18:33 Chep 阅读(224) 评论(0)  编辑 收藏


标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
 
另存  打印