Drag images from IE to vb.net application

W

William

I am creating an application to categorize images from websites. I
have tried a few sets of sample code to try to copy the image when it
is dropped into my vb.net application but it seem that the dragdrop
event never fires. I have enabled the AllowDrop. Does anyone have
any sample code or suggestion?

Thanks,

William
 
K

Ken Tucker [MVP]

Hi,

Set the picturebox1.allowdrop=true. This should allow to
drag an image from a webpage to the picturebox.
Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter

If e.Data.GetDataPresent(DataFormats.FileDrop, False) Then

Dim strFile() As String = CType(e.Data.GetData(DataFormats.FileDrop),
String())

Dim fi As New System.IO.FileInfo(strFile(0))

If fi.Extension = ".gif" Or fi.Extension = ".bmp" Or _

fi.Extension = ".jpg" Or fi.Extension = ".jpeg" Then

e.Effect = DragDropEffects.Copy

End If

End If

End Sub

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

Dim s() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())

Dim fs As New System.IO.FileStream(s(0), IO.FileMode.Open)

Dim bm As New Bitmap(fs)

fs.Close()

PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

PictureBox1.Image = bm

End Sub



Ken

--------------------------

I am creating an application to categorize images from websites. I
have tried a few sets of sample code to try to copy the image when it
is dropped into my vb.net application but it seem that the dragdrop
event never fires. I have enabled the AllowDrop. Does anyone have
any sample code or suggestion?

Thanks,

William
 
W

William

Thanks Ken,

This code works good, it does not work with images with links
associated to them it there a way around this. Please let me know


Thanks,

William
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top