How do I create a dynamic mouse cursor .NET without using interop?

前端 未结 4 934
有刺的猬
有刺的猬 2021-01-20 08:01

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.

I would like to load a c

4条回答
  •  清歌不尽
    2021-01-20 08:32

    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
    

提交回复
热议问题