2
我有這個問題:我創建了一個自定義控件(C#,WinForms,框架4.0),其中我需要改變光標時,用戶按下某個鍵(這工作);退出控制我想恢復到以前的光標..但這不起作用:退出光標保持當前一個。怎麼了?光標不改變自定義控制出口
protected override void OnMouseEnter(EventArgs e)
{
oldCursor = Cursor;
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
Cursor = oldCursor;
base.OnMouseLeave(e);
}
當按下按鈕,我做的事:
this.Cursor = NewCursor.CreateCursor(
Properties.Resources.cur_ZoomIn, 14, 9, Color.White);
其中
public static Cursor CreateCursor(
Bitmap bmp_parm, int xHotSpot, int yHotSpot, Color? transparent)
{
Image img = bmp_parm;
Bitmap bmp = new Bitmap(img, new Size(img.Width, img.Height));
if (transparent.HasValue) bmp.MakeTransparent(transparent.Value);
if (cursor != IntPtr.Zero)
DestroyIcon(cursor);
IntPtr ptr = bmp.GetHicon();
IconInfo tmp = new IconInfo();
GetIconInfo(ptr, ref tmp);
tmp.xHotspot = xHotSpot;
tmp.yHotspot = yHotSpot;
tmp.fIcon = false;
cursor = CreateIconIndirect(ref tmp);
if (tmp.hbmColor != IntPtr.Zero) DeleteObject(tmp.hbmColor);
if (tmp.hbmMask != IntPtr.Zero) DeleteObject(tmp.hbmMask);
if (ptr != IntPtr.Zero) DestroyIcon(ptr);
return new Cursor(cursor);
}
我用Google搜索周圍(例如here和其他地方)和我的代碼似乎是正確的......
是@VMAtm,你是對的(我已經考慮過了),謝謝你的回答!問題是我沒有保存和恢復遊標的經驗... – Marco
@Marco沒問題,歡迎您。感謝良好的問題質量和祝你好運:) – VMAtm
@Marco或者你仍然有問題呢? – VMAtm