程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 在.NET中實現彩色光標,動畫光標和自定義光標

在.NET中實現彩色光標,動畫光標和自定義光標

編輯:C#入門知識

下面是完整的例子,可以通過命令行編譯即可看到效果。

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:WINNTCursorsdinosau2.ani" ); myCursor.GetType().InvokeMember("handle",BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField,null,myCursor, new object [] { colorCursorHandle } ); this.Cursor = myCursor; } } }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved