工作中經常需要自訂滑鼠樣式來更豐富更形象地互動操作,系統內建的樣式單一,難免會有些審美疲勞.取而代之,用一些比較形象的表徵圖來定義滑鼠樣式,使用者體驗上就更加形象了. 自訂滑鼠樣式
/// <summary>
/// 自訂滑鼠樣式
/// </summary>
/// <param name="cursor">一張背景透明的圖片,格式為(png/gif)</param>
/// <param name="hotPoint"></param>
public static System.Windows.Forms.Cursor SetCursor(System.Drawing.Bitmap cursor, System.Drawing.Point hotPoint)
//設定滑鼠樣式
{
int hotX = hotPoint.X;
int hotY = hotPoint.Y;
System.Drawing.Bitmap myNewCursor = new System.Drawing.Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(myNewCursor);
g.Clear(System.Drawing.Color.FromArgb(0, 0, 0, 0));
g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width, cursor.Height);
System.Windows.Forms.Cursor newCursor = new System.Windows.Forms.Cursor(myNewCursor.GetHicon());
g.Dispose();
myNewCursor.Dispose();
return newCursor;
}