发布网友 发布时间:2022-04-23 02:56
共1个回答
热心网友 时间:2023-06-22 21:14
[DllImport("user32.dll")]
static extern IntPtr LoadCursorFromFile(string lpFileName);
[DllImport("user32.dll")]
static extern IntPtr SetCursor(IntPtr hCursor);
[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);
private const uint OCR_NORMAL = 32512;
static Cursor ColoredCursor;
//==========C# Only
//========SET WINDOWS CURSOR========================================
IntPtr cursor = LoadCursorFromFile("example.cur");
bool ret_val = SetSystemCursor(cursor, OCR_NORMAL);
//========SET WINDOWS CURSOR========================================
//========SET FORM CURSOR========================================
IntPtr cursor = LoadCursorFromFile("example.cur");
ColoredCursor = new Cursor(cursor);
this.Cursor = ColoredCursor;
//========SET FORM CURSOR========================================
//========SET FORM CURSOR FROM IMAGE========================================
Bitmap hh = (Bitmap)System.Drawing.Bitmap.FromFile("example.png");
Graphics.FromImage(hh);
IntPtr ptr = hh.GetHicon();
Cursor c = new Cursor(ptr);
this.Cursor = c;
//========SET FORM CURSOR FROM IMAGE========================================