当前位置:网站首页>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
边栏推荐
- 添加环境路径
- 不谈赛道,不聊风口,开源数据库巨头Cassandra如何在国内讲好“新故事” | C位面对面
- Kubernetes binary installation (v1.20.16) (V) verifying master deployment
- 漫谈软件缺陷与漏洞
- 想要实现在时序场景下“远超”通用数据库,需要做到哪几点?
- How to write high-performance code (IV) optimize data access
- Dbutil auxiliary class, manual commit transaction, metadata
- QQ pulls up Alipay H5 payment function
- [background interaction] select to bind the data transferred in the background
- . The way to prove the effect of throwing exceptions on performance in. Net core
猜你喜欢

31w赛题奖金!当 AI for Science 撞上“先导杯”,会擦出什么样的火花?

CS structure and BS structure
![[arcgis] City relevance analysis](/img/f4/454266e1ed586240bce9a7f36aa52e.png)
[arcgis] City relevance analysis
Go语言学习之WaitGroup用法详解

高比例风电电力系统储能运行及配置分析(Matlab实现)

Bs-xx-007 registered residence management system based on JSP

字节真的是宇宙尽头吗?

Teatalk · online speech record | complete! It is important to select the right data migration strategy for safe cloud deployment

NFT市场怎么样 为什么NFT能如此火爆 怎么搭建NFT平台

一个时代的终结!十年了吴恩达经典《机器学习》课程本月关闭注册,上线新课!...
随机推荐
@How to resolve controller and requestmapping
逆向学习入门-优秀的汇编调试工具OllyDbg
TeaTalk·Online 演讲实录 | 圆满完结!安全上云,选对数据迁移策略很重要
Terraform + Ansible实现基础设施及配置管理
中国 SaaS 发展落后美国 10 年,仍需借助创新、开源、并购等策略发力 | ArchSummit
Is byte really the end of the universe?
After five years of losing the lawsuit, the trillion reptile army is ready to move
Quic resistance
live share使用体验
微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!
长连接简介
What do you need to do to "surpass" the general database in the time sequence scenario?
马斯克称自己不喜欢做CEO,更想做技术和设计;吴恩达的《机器学习》课程即将关闭注册|极客头条...
Musk says he doesn't like being a CEO, but rather wants to do technology and design; Wu Enda's "machine learning" course is about to close its registration | geek headlines
How to synchronize openstack RDO source to local for offline installation
shader着色器
In 2022, capture these 12 data and analyze trends!
Jdbctemplate data background management. I don't know why roleid is empty when adding users
On software defects and loopholes
一个时代的终结!十年了吴恩达经典《机器学习》课程本月关闭注册,上线新课!...