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

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


在.net中实现彩色光标,动画光标和自定义光标
作者:孟宪会
出自:【孟宪会之精彩世界】
发布日期:2004年10月22日 8 


下面是完整的例子,
可以通过命令行编译即可看到效果。 
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;
  }
}
}    (2005-11-16:04:36)

 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 您可能对 [C#] 的这些文章也感兴趣:

用C#创建Web应用程序
C#实现数字金额向大写金额的转换
Singleton设计模式的C#实现(2)
总体了解C#(2)
用VisualC#做托盘程序
通过实例学习C#开发中的泛型
ASP.NET追捕休整版
C#2.0新特性探究(二)委托与匿名委托
实例 C# 学习使用StatusStrip
VisualStudio.Net内幕(5)