I want to use an image or icon as a custom cursor in WPF app. What's the best way to do it?
相关问题
- Views base64 encoded blob in HTML with PHP
- How to get the background from multiple images by
- Generic Generics in Managed C++
- VNC control for WPF application
- How to Debug/Register a Permanent WMI Event Which
相关文章
- .net中MessageBox.Show使用问题
- IdentityServer 报错:"idp claim is missing"
- 在 IdentityServer 中如何给 id token 添加更多信息
- WPF:如何在Trigger里修改Orientation?
- IdentityServer 的 Selector 在哪个 nuget 包
- 使用 IdentityServer 的项目遭遇错误:"IDX20803: Unable to obt
- ASP.NET Core ConfigureServices 中从 appsettings.json
- WPF aforge 怎么做一个 圆形的播放器
In case anyone is looking for a UIElement itself as a cursor, I combined the solutions of Ray and Arcturus:
Here's a feature-rich, free utility that allows you to create a cur file from any image: http://www.rw-designer.com/cursor-maker
It's called RealWorld Cursor Editor.
And here's a link on how to embed a cursor in a project:
http://wpf.2000things.com/tag/cursor/
you can do this by Code like
One more solution somewhat similar to Ray's but instead of slow and cumbersome pixel copying, this uses some Windows internals:
There is an extension method in the middle that I prefer to have in an extension class for such cases:
With all this, it's rather simple and straightforward.
And, if you happen not to need to specify your own hotspot, you can even cut this shorter (you don't need the struct or the P/Invokes, either):
Make sure, that any GDI resource (for example bmp.GetHIcon) gets disposed. Otherwise you end up with a memory leak. The following code (extension method for icon) works perfectly for WPF. It creates the arrow cursor with a small icon on it's lower right.
Remark: This code uses an icon to create the cursor. It does not use a current UI control.
Matthias
If you are using visual studio, you can