Drawing an Image from the cursor

  • Thread starter Thread starter Tom C
  • Start date Start date
T

Tom C

I see a lot of posts about creating a cursor from an image but is it
possible to do the opposite?

We have added code to allow a text box on a statusbar to be dragged to
allow dropping an open window on another icon, grid, etc. It would be
very intuitive for the user if we could grab the default cursor and
render this as an image next to the text box.

Anyone have any ideas how this could be done?
 
This should do it:

Dim cur As Cursor = Me.Cursor 'Or whichever cursor
Dim bmp As New Drawing.Bitmap(cur.Size.Width, cur.Size.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
me.Cursor.Draw(g,new
Rectangle(0,0,cur.Size.Width,cur.Size.Height)
g.Dispose()
PictureBox1.Image = bmp
bmp.Dispose()


Good luck,

-Mark
 
This should do it:

Dim cur As Cursor = Me.Cursor 'Or whichever cursor
Dim bmp As New Drawing.Bitmap(cur.Size.Width, cur.Size.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
me.Cursor.Draw(g,new
Rectangle(0,0,cur.Size.Width,cur.Size.Height)
g.Dispose()
PictureBox1.Image = bmp
bmp.Dispose()

Good luck,

-Mark
Mark,

Thanks very much for the input. I had to comment out the dispose of
the bitmap. That was causing a very nasty error. I ended up with this:

Dim cur As Cursor = Cursors.Default
Dim bmp As New Drawing.Bitmap(cur.Size.Width,
cur.Size.Height)
Dim g As System.Drawing.Graphics =
System.Drawing.Graphics.FromImage(bmp)
Try
Me.Cursor.Draw(g, New System.Drawing.Rectangle(0, 0,
cur.Size.Width, cur.Size.Height))
Me.ToolStripStatusLabelObjectId.Image = bmp
Finally
' bmp.Dispose()
g.Dispose()
End Try
 
Back
Top