设置窗体光标样式
Demo
==================================================================
该例子光标在程序的UI文件夹下,如果使用需修改位置。
#region 光标样式
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr LoadCursorFromFile(string fileName);
/// <summary>
/// 设置光标样式 .ani 或者.cur文件
/// </summary>
/// <param name="cursorsName">光标样式名称</param>
/// <param name="form">被设置的窗体</param>
public static void SetCursorStyle(string cursorsName, System.Windows.Forms.Form form)
{
try
{
System.Windows.Forms.Cursor myCursor;
myCursor = new System.Windows.Forms.Cursor(System.Windows.Forms.Cursor.Current.Handle);
//光标样式位置
string path = System.Windows.Forms.Application.StartupPath + "//UI//" + cursorsName;
IntPtr colorCursorHandle = LoadCursorFromFile(path);
myCursor.GetType().InvokeMember("handle", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetField, null, myCursor, new object[] { colorCursorHandle });
form.Cursor = myCursor;
}
catch (Exception)
{
}
}
#endregion