问题描述
我有一个我最终希望移植到mono的应用程序,因此我试图避免使用p/invoke来完成此任务.
I have an application which I'm interested in eventually porting to mono so I'm trying to avoid using p/invoke's to accomplish this task.
我想动态地加载一个游标,因为我有一个在应用程序中动态生成的位图.据我所知,最安全的方法是不使用p/invoke的方法是创建一个.cur文件,然后将其加载到内存流中并使用 Cursor(Stream)构造函数.但是我不知道如何创建一个.cur文件.
I would like to load a cursor dynamically, as in I have a Bitmap that is generated on the fly in the application. From what I can tell the safest way to do it without using p/invoke's is to create a .cur file which I can then load to a memory stream and use the Cursor(Stream) constructor. However I have no idea how to create a .cur file.
我在Microsoft知识库中找到了这篇文章,其中解释了这种格式,但是我不确定如果没有互操作调用该如何使用它. 如何在Windows XP中创建Alpha混合光标或图标
I found this article on the Microsoft Knowledge Base which sort of explains the format, but I'm not sure how it can be used without the interop calls. How To Create an Alpha Blended Cursor or Icon in Windows XP
其他人是否可以使用托管解决方案来完成此任务?
Does anyone else have a managed solution I can use to accomplish this task?
推荐答案
下面是VB.NET中的一个示例,该示例动态创建位图并将其转换为光标.不确定谁能对7年以上的时间有所帮助,但是可以这样:
Here's an example in VB.NET of creating a bitmap on the fly and turning it into a cursor. Not sure who this will help 7+ years on, but here goes:
Private Function GetCircleCursor(iDiameter As Integer) As Cursor
Dim oBitmap As Bitmap = New Bitmap(Convert.ToInt32(iDiameter), Convert.ToInt32(iDiameter), System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Using g As System.Drawing.Graphics = Graphics.FromImage(oBitmap)
g.Clear(Color.Transparent)
g.DrawEllipse(New System.Drawing.Pen(Color.White, 3), New Rectangle(0, 0, iDiameter, iDiameter))
g.DrawEllipse(New System.Drawing.Pen(Color.Black, 1), New Rectangle(0, 0, iDiameter, iDiameter))
End Using
Return New Cursor(oBitmap.GetHicon)
End Function
这篇关于如何在不使用互操作的情况下创建动态鼠标光标.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!