Results 1 to 4 of 4

Thread: [RESOLVED] Drag and Drop from explorer

  1. #1
    MonkeyMadness
    Guest

    Resolved [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

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    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:
    1. Dim S() As String = e.Data.GetData("FileName")
    2. 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...

  3. #3
    MonkeyMadness
    Guest
    I'll give that a try.

    Thanks

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    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:
    1. Dim im As Image = Nothing
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         PictureBox1.AllowDrop = True
    5.     End Sub
    6.  
    7.     Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
    8.         Dim file() As String
    9.         If e.Data.GetDataPresent("FileNameW") Then
    10.             file = e.Data.GetData("FileNameW")
    11.             im = Image.FromFile(file(0))
    12.             e.Effect = DragDropEffects.Move
    13.         End If
    14.     End Sub
    15.  
    16.     Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
    17.         If Not im Is Nothing Then
    18.             e.Effect = DragDropEffects.Move
    19.             PictureBox1.Image = im
    20.         End If
    21.     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
  •  



Click Here to Expand Forum to Full Width