C#如何修改桌面上鼠标指针形状

发布网友 发布时间: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========================================

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com