当前位置:网站首页>C # set the cursor shape of forms and systems
C # set the cursor shape of forms and systems
2022-06-11 13:22:00 【Non entropy~】
During the development process, it is found that it is necessary to change the mouse style ( Cursor Icon ), We may set the cursor shape in a single form or the cursor shape in the system , We can create system cursor files (CUR file ) To replace the cursor shape , You can also replace the cursor shape with a picture .
Instance Links :c# Set the cursor shape of forms and systems ( Use cur or png)- Desktop system document resources -CSDN download
One 、 adopt CUR File set form cursor shape
/// <summary>
/// Set the form cursor
/// </summary>
/// <param name="cursor"></param>
/// <param name="hotPoint"></param>
public void SetCursor(Bitmap cursor, Point hotPoint)
{
int hotX = hotPoint.X;
int hotY = hotPoint.Y;
Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY);
Graphics g = Graphics.FromImage(myNewCursor);
g.Clear(Color.FromArgb(0, 0, 0, 0));
g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width,
cursor.Height);
this.Cursor = new Cursor(myNewCursor.GetHicon());
g.Dispose();
myNewCursor.Dispose();
}
private void btnSetFormCursor_Click(object sender, EventArgs e)
{
this.Cursor = new Cursor("my.cur");
}
private void btnRestoreFormCursor_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.Arrow;
}Two 、 Set the form cursor shape through the picture file
/// <summary>
/// Set the form cursor
/// </summary>
/// <param name="cursor"></param>
/// <param name="hotPoint"></param>
public void SetCursor(Bitmap cursor, Point hotPoint)
{
int hotX = hotPoint.X;
int hotY = hotPoint.Y;
Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY);
Graphics g = Graphics.FromImage(myNewCursor);
g.Clear(Color.FromArgb(0, 0, 0, 0));
g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width,
cursor.Height);
this.Cursor = new Cursor(myNewCursor.GetHicon());
g.Dispose();
myNewCursor.Dispose();
}
private void btnSetCursorByPng_Click(object sender, EventArgs e)
{
Bitmap a = (Bitmap)Bitmap.FromFile("my.png");
SetCursor(a, new Point(0, 0));
}
private void btnStoreCursorByPng_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.Arrow;
}3、 ... and 、 Set and cancel the system cursor shape
/// <summary>
/// Cursor resource loading function
/// </summary>
/// <param name="fileName"> Under load path .cur file </param>
/// <returns></returns>
[DllImport("User32.DLL")]
public static extern IntPtr LoadCursorFromFile(string fileName);
/// <summary>
/// Set system pointer function ( use hcur Replace id Defined cursor )
/// </summary>
/// <param name="hcur"></param>
/// <param name="id"></param>
/// <returns></returns>
[DllImport("User32.DLL")]
public static extern bool SetSystemCursor(IntPtr hcur, uint id);
public const uint OCR_NORMAL = 32512;
public const uint OCR_IBEAM = 32513;
/// <summary>
/// System level parameter functions queried or set
/// </summary>
/// <param name="uiAction"></param>
/// <param name="uiParam"></param>
/// <param name="pvParam"></param>
/// <param name="fWinIni"></param>
/// <returns></returns>
[DllImport("User32.DLL")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
public const uint SPI_SETCURSORS = 87;
public const uint SPIF_SENDWININICHANGE = 2;
/// <summary>
/// Set the system cursor
/// </summary>
private void SetCursor()
{
IntPtr hcur_click = LoadCursorFromFile("my.cur");
SetSystemCursor(hcur_click, OCR_NORMAL);
SetSystemCursor(hcur_click, OCR_IBEAM);
Set up mobile
//cur = LoadCursorFromFile("my.cur");
//SetSystemCursor(cur, OCR_SIZEALL);
Settings not available
//cur = LoadCursorFromFile("my.cur");
//SetSystemCursor(cur, OCR_NO);
Set hyperlink
//cur = LoadCursorFromFile("my.cur");
//SetSystemCursor(cur, OCR_HAND);
}
// Restore the system cursor
SystemParametersInfo(SPI_SETCURSORS, SPIF_SENDWININICHANGE, IntPtr.Zero, SPIF_SENDWININICHANGE);Reference resources :
CUR Documentation :https://jingyan.baidu.com/article/afd8f4de444fad75e286e9f4.html
边栏推荐
- BS-XX-007基于JSP实现户籍管理系统
- 如何写出高性能代码(四)优化数据访问
- Go 如何减少供应链攻击?
- After five years of losing the lawsuit, the trillion reptile army is ready to move
- kubernetes 二进制安装(v1.20.15)(七)加塞一个工作节点
- QQ pulls up Alipay H5 payment function
- [acwing 11. solution number of knapsack problem] 01 knapsack + 01 knapsack + understand the specific meaning of 01 knapsack
- 风电随机性动态经济调度模型(Matlab代码实现)
- 在启牛开的证券账户安全吗?如何申请低佣金的股票账户?
- 苹果将造搜索引擎?
猜你喜欢

字节真的是宇宙尽头吗?

Using vscode code code template to improve mobx coding efficiency

Network information system emergency response

On the continuing Life of Distributed Locks - - Distributed Locks Based on redis

BS-XX-007基于JSP实现户籍管理系统
![[background interaction] select to bind the data transferred in the background](/img/4d/ef3517a2b3f28f14ad87f16780e246.png)
[background interaction] select to bind the data transferred in the background
![[arcgis] City relevance analysis](/img/f4/454266e1ed586240bce9a7f36aa52e.png)
[arcgis] City relevance analysis

为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.

ecplise无法连接sql server

苹果将造搜索引擎?
随机推荐
Huawei HECs ECS is used to build a telegraf+influxdb+grafana monitoring system [Huawei cloud to jianzhiyuan]
cadence SPB17.4 - group operation(add to group, view group list, delete group)
About PHP: the original deployment environment written by PHP is deployed in phpstudy, PHP + MySQL + Apache. However, the computer must be turned on every time
网络信息系统应急响应
字节真的是宇宙尽头吗?
为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.
JDBC连接池去做批量导入,每次运行500万数据,但是在中间就会出各种问题
[acwing 11. solution number of knapsack problem] 01 knapsack + 01 knapsack + understand the specific meaning of 01 knapsack
一个时代的终结!十年了吴恩达经典《机器学习》课程本月关闭注册,上线新课!...
On the continuing Life of Distributed Locks - - Distributed Locks Based on redis
Go语言学习之WaitGroup用法详解
Quic resistance
[arcgis] City relevance analysis
What do you need to do to "surpass" the general database in the time sequence scenario?
Unity 检测对象是否在相机的视锥体范围内
刚高考完有些迷茫不知道做些什么?谈一谈我的看法
Dbutil auxiliary class, manual commit transaction, metadata
[bug resolution] after uploading the image, cancel the upload and upload again. The last image still exists
长连接简介
LNMP部署