[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 uiAction,
UInt32 uiParam, String pvParam, UInt32 fWinIni);
[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);
Cursor BlankCursor;
private void CreateBlankCursor()
{
Bitmap bitmapcursor = new Bitmap(16, 16);
Graphics g = Graphics.FromImage(bitmapcursor);
g.FillRectangle(Brushes.Transparent, 0, 0, 16, 16);
IntPtr ptrCur = bitmapcursor.GetHicon();
BlankCursor = new Cursor(ptrCur);
}
static public void RevertCursors()
{
SystemParametersInfo(0x0057, 0, null, 0);
}
private void Form1_Load(object sender, EventArgs e)
{
//Set Blank cursor here
System.Threading.Thread.Sleep(3000);
RevertCursors();
}
在Form_Load中,我必须将SytemCursor设置为BlankCursor,因为我已经编写了上面的代码,经过一段时间后,它将恢复为默认的箭头光标。