Display An image while dragging it.

jimirayyng

Member
Joined
Apr 22, 2009
Messages
8
Location
hampshire uk
Programming Experience
5-10
Guys,

I am dragging a picture box to another picture box using dragdrop methods. All is working fine but i would like to display a copy of the image while it is being dragged.. like a ghost image
can anyone give me some rough ideas on how to do this please.

Thanks

Jimi :)
 
Hi JimiRayyng (if you're still listening)

You should be able to piece something together from these hints:

1. If you're using the standard drag/drop technique, you can specify any cursor in the GiveFeedback event handler of a control.

2. You can turn any bitmap into a cursor like this:
VB.NET:
Dim cur As New Cursor(myBitmap.GetHicon)

3. Here's a function to set the transparency of a bitmap:
VB.NET:
Function FadeImage(ByVal img As Image, ByVal OpacityPercent As Integer) As Bitmap
        Dim bmp As New Bitmap(img.Width, img.Height)
        Dim cm As New Drawing.Imaging.ColorMatrix
        cm.Matrix33 = OpacityPercent / 100.0F
        Using ia As New Drawing.Imaging.ImageAttributes
            ia.SetColorMatrix(cm)
            Using g As Graphics = Graphics.FromImage(bmp)
                g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height), _
                                  0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia)
                Return bmp
            End Using
        End Using
    End Function

cheers, VicJ
 
I forgot to say in my last post, but I don't totally trust that cursor conversion. I've discovered it can cause memory errors with very large images (> 16 million pixels). Probably it won't cause problems with smaller images, but I'd suggest putting it in a Try-Catch block to deal with any exception that might be thrown when you create the custom cursor.

cheers BB
 
Back
Top