C# Winforms 中的自定义光标
有谁知道使用自定义光标的简单方法?我的光标有 .cur 和 .png。我尝试将其作为资源添加到我的项目中,并尝试将其作为文件包含在项目中。理想情况下,我想嵌入它,但我只想让它工作。
当我使用 Cursor cur = new Cursor("mycursor.cur") 时,我收到“图像格式无效。图像文件可能已损坏”。我尝试过这个 http://mahesg.wordpress.com/2008/02/09 /embedding-cursor/ 但它不起作用。使用 WinForm1.Properties.Resources.mycursor 返回一个 byte[],我不知道如何将其转换为 Cursor 类型。
Does anyone know of an easy way to use a custom cursor? I have both a .cur and .png of my cursor. I tried adding it as a resource to my project and also tried including it as a file in the project. Ideally I'd like to embed it but I just want to get it working.
When I use Cursor cur = new Cursor("mycursor.cur")
I get "Image format is not valid. The image file may be corrupted". I tried this http://mahesg.wordpress.com/2008/02/09/embedding-cursor/ but it didn't work. Using WinForm1.Properties.Resources.mycursor
returns a byte[] which I have no idea how to convert into a Cursor type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于某种原因,游标类对于它将读取的内容过于挑剔。您可以使用 Windows API 自己创建句柄,然后将其传递给游标类。
C#:
VB.Net:
For some reason the cursor class is far too picky about what it will read. You can create the handle yourself using the windows API then pass that to the cursor class.
C#:
VB.Net:
写入 new Cursor(new MemoryStream(Properties.Resources.mycursor))
Write
new Cursor(new MemoryStream(Properties.Resources.mycursor))
在 C# 中向光标添加自定义图标:
将图标文件添加到项目资源(例如:Processing.ico)
并在图像的属性窗口中将“构建操作”切换为“嵌入”
例如:
Adding custom icon to cursor in C# :
Add Icon file to Project resources (ex : Processing.ico)
And in properties window of image switch "Build Action" to "Embedded"
Ex:
目标:当用户需要在示例 winforms UI 中执行剪切活动时,将光标更改为自定义光标
执行此操作将会起作用
要添加到资源,请右键单击项目 -> 属性 -> 资源 现在将 ico 文件从项目文件夹(U 添加到第 1 点中的项目文件夹)中拖放到资源上
Objective: To change cursor to a custom cursor when user need to do cut activity in a sample winforms UI
Do this it will work
To add to resource right click on project->properties->Resources Now drop the ico file from the project folder (U added to project folder in point 1) on Resources