Mouse Drag - Use Image

papa_k

Member
Joined
Jun 1, 2009
Messages
22
Programming Experience
1-3
Hi,

I want a user to be able to drag and drop a file. I want the drag and drop to interigate that file and extract an image from it. I then want the mouse cursor to then be that image (or at least include it as it's dragged) thus informing the user of the image they are dragging.

Is this possible within the VS08 vb.net arena?

Papa
 
You have to make an icon from the image, set the cursor to this in the GiveFeedback Event.

VB.NET:
'MouseDown
bmp = CType(Image.FromFile("your.bmp"), Bitmap)
cur = New Cursor(bmp.GetHicon)
bmp.Dispose()
'GiveFeedback
If (e.Effect = DragDropEffects.All) Then
   e.UseDefaultCursors = False
   Cursor.Current = cur
Else
   e.UseDefaultCursors = True
   Cursor.Current = Cursors.Default
End If
 
Hi,

Thanks for this. Unfortunately it doesn't work in its current form. I have tried to fix the code and this is what i came up with:

VB.NET:
            Dim bmp
            Dim cur As Cursor
            bmp = CType(Image.FromFile("C:\Users\Papa\Documents\test-image.bmp"), Bitmap)
            cur = bmp.GetHicon
            bmp.Dispose()
            'GiveFeedback
            If (e.Effect = DragDropEffects.All) Then
                e.UseDefaultCursors = False
                Cursor.Current = cur
            Else
                e.UseDefaultCursors = True
                Cursor.Current = Cursors.Default
            End If

The error it gives when i tray to run it is

[error]
Unable to cast object of type 'System.IntPtr' to type 'System.Windows.Forms.Cursor'
[/error]
 
Sure in my version; bmp, and cur are declared at the class level so I can reference them in both events. Your cur does not initiate a new cursor supplying the single parameter of the new bmp.GetHicon. There are two events happening, Mousedown = make the bmp, then change the bmp into a cursor, GiveFeedback = use the cursor when appropiate.
 
Back
Top