在resource文件中置入cur文件
private const uint OCR_NORMAL = 32512;
[DllImport("user32.dll")]
private static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll")]
private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref IntPtr pvParam, uint fWinIni);
private const uint SPI_SETCURSORS = 0x0057;
private const uint SPIF_UPDATEINIFILE = 0x01;
private const uint SPIF_SENDCHANGE = 0x02;
private static readonly IntPtr IDC_ARROW = new IntPtr(32512);
private static void SetDefaultCursor()
{
IntPtr cursorHandle = IDC_ARROW;
SystemParametersInfo(SPI_SETCURSORS, 0, ref cursorHandle, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
public string colorRGBtoHx16(int R, int G, int B)
{
return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
}
private void button1_Click(object sender, EventArgs e)
{
try {
System.IO.MemoryStream cursorMemoryStream = new System.IO.MemoryStream(Properties.Resources.pen);
Cursor c = new Cursor(cursorMemoryStream);
SetSystemCursor(c.Handle, OCR_NORMAL);
}
catch { }
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Cursor.Current = Cursors.Default;
}
标签:IntPtr,const,cur,C#,System,private,uint,static,光标 From: https://www.cnblogs.com/guangzhiruijie/p/17656352.html