当前位置:网站首页>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
边栏推荐
- Customize terrain providers (terrain plugin framework) -04
- Hashicopy之nomad应用编排方案07(提交Job)
- Is byte really the end of the universe?
- 如何学会花钱
- 漫谈软件缺陷与漏洞
- 苹果将造搜索引擎?
- Ecplise cannot connect to SQL Server
- Can't understand kotlin source code? Starting with the contracts function~
- [problem summary] $t
- 火山引擎云数据库 veDB 在字节内部的业务实践
猜你喜欢

cadence SPB17.4 - allegro - allegro_free_viewer

求你了,不要再在对外接口中使用枚举类型了!

JSP实现银柜台业务绩效考核系统
![InfoQ geek media's 15th anniversary essay solicitation - dynamic ranking of mobile terminal development [mui+flask+mongodb]](/img/92/50a92eb6b5c2ac3f58c499796a1e8c.png)
InfoQ geek media's 15th anniversary essay solicitation - dynamic ranking of mobile terminal development [mui+flask+mongodb]

TeaTalk·Online 演讲实录 | 圆满完结!安全上云,选对数据迁移策略很重要

字节真的是宇宙尽头吗?

利用 VSCode 的代码模板提高 MobX 的编码效率
![[bug resolution] the form is paged to display the total data res.data total](/img/92/1ddde16d35465f8dd53ebf90e249b8.png)
[bug resolution] the form is paged to display the total data res.data total

Introduction to long connection

On the continuing Life of Distributed Locks - - Distributed Locks Based on redis
随机推荐
使用华为HECS云服务器打造Telegraf+Influxdb+Grafana 监控系统【华为云至简致远】
想要实现在时序场景下“远超”通用数据库,需要做到哪几点?
Interview to build an aircraft carrier, screw on the job, pay
[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]
Terraformer importing cloud resources
Dbutil auxiliary class, manual commit transaction, metadata
Is the securities account opened in qiniu safe? How to apply for a low commission stock account?
微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!
Network information system emergency response
看不懂Kotlin源码?从Contracts 函数说起~
On the life extension of distributed locks -- redis based distributed locks
一个时代的终结!十年了吴恩达经典《机器学习》课程本月关闭注册,上线新课!...
深度学习与CV教程(14) | 图像分割 (FCN,SegNet,U-Net,PSPNet,DeepLab,RefineNet)
Terraform + Ansible实现基础设施及配置管理
From real-time computing to streaming data warehouse, where will Flink go next?
【信号处理】数字信号处理Matlab设计附GUI界面和报告
Some transformation thoughts of programmers after they are 35 years old
Using vscode code code template to improve mobx coding efficiency
火山引擎云数据库 veDB 在字节内部的业务实践
启牛商学院给的券商账户是安全的吗?开户收费吗