[Help] Drag-drop images.

Posts 1–5 of 5 · Page 1 of 1
[Help] Drag-drop images.
Hey guys.

Anyone know how to make a picturebox display an image I drag and drop into it from the internet. Similar to what you can do with microsoft word etc, how you drag the picture and drop it on the form and poof, it displays it there.

Hope you catch my drift

Cheers,

J-Deezy.
Code:
Public Class Form1

    Private Sub form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim DroppedFiles As String() = _
                  e.Data.GetData(DataFormats.FileDrop)
            For i As Int32 = 0 To DroppedFiles.Length - 1
            
                PictureBox1.ImageLocation = DroppedFiles(i)

            Next
        End If
    End Sub

    Private Sub form1_DragEnter(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.DragEventArgs) Handles _
     Me.DragEnter

        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.AllowDrop = True
    End Sub
End Class
Figured it out for you =D

Add Try-Catch-Blocks etc...

Enjoy!
Quote Originally Posted by Blubb1337 View Post
Code:
Public Class Form1

    Private Sub form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim DroppedFiles As String() = _
                  e.Data.GetData(DataFormats.FileDrop)
            For i As Int32 = 0 To DroppedFiles.Length - 1
                'ListBox1.Items.Add(DroppedFiles(i))
                PictureBox1.ImageLocation = DroppedFiles(i)

            Next
        End If
    End Sub

    Private Sub form1_DragEnter(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.DragEventArgs) Handles _
     Me.DragEnter

        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.AllowDrop = True
    End Sub
End Class
Figured it out for you =D

Add Try-Catch-Blocks etc...

Enjoy!
You sir, are too good.
Problem solved ?
Indeed it is.
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us