|
-
Jan 3rd, 2004, 12:07 PM
#1
[RESOLVED] Drag and Drop from explorer
I have managed to drag and drop an image from one picturebox to another but I cannot figure out how to open up windows explorer and drag the image file from explorer to the picturebox.
The picturebox with the DragDrop method is below.
Private Sub Fcover_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Fcover.DragDrop
Me.Fcover.Image = e.Data.GetData(DataFormats.Bitmap)
End Sub
The method is firing but the image doesnt appear.
Any ideas what I am doing wrong ?
Is it also possible to find the name and location of the file I drag ?
TIA
-
Jan 3rd, 2004, 05:37 PM
#2
Hi.
This is because, the dataformat is not a bitmap.
When you drag a file from the explorer, it's only a string, containing the filename.
So instead of retrieving the bitmap directly, you should retrieve the filename, and then use something like :
VB Code:
Dim S() As String = e.Data.GetData("FileName")
Me.Fcover.Image = Image.FromFile(S(0))
I haven't tested this, so it may need a little adjustment, but in theory it should work.
Good luck.
Last edited by pax; Jan 3rd, 2004 at 05:49 PM.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Jan 3rd, 2004, 07:41 PM
#3
I'll give that a try.
Thanks
-
Jan 5th, 2004, 06:44 AM
#4
after quite a bit of messing about i managed to get something working which hopefully is what you need , you should look at the dataformat " FileNameW " , this holds the full path of your file. eg:
VB Code:
Dim im As Image = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.AllowDrop = True
End Sub
Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
Dim file() As String
If e.Data.GetDataPresent("FileNameW") Then
file = e.Data.GetData("FileNameW")
im = Image.FromFile(file(0))
e.Effect = DragDropEffects.Move
End If
End Sub
Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
If Not im Is Nothing Then
e.Effect = DragDropEffects.Move
PictureBox1.Image = im
End If
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|