.NET中實現(xiàn)彩色光標、動畫光標及自定義光標的方法
更新時間:2014年08月19日 09:47:23 投稿:shichen2014
這篇文章主要介紹了.NET中實現(xiàn)彩色光標、動畫光標及自定義光標的方法,非常實用的功能,需要的朋友可以參考下
本文所述實例主要完成dotNET中實現(xiàn)彩色光標、動畫光標及自定義光標的功能。以下是完整的程序?qū)嵗梢酝ㄟ^命令行編譯可看到運行效果。
Test.cs頁面代碼如下:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
namespace ColorCursor
{
/// <summary>
/// 本例子的作用:
/// 在.NET中實現(xiàn)彩色光標,動畫光標和自定義光標。
/// </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://m.fzitv.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#程序設計能夠起到一定的幫助作用。
您可能感興趣的文章:

