Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2012 Drag and Drop Images from web browser into a PictureBox?

$
0
0
Hi guys, I'm making an app that needs to drag images from the browser into a picturebox inside my app, from which I will later save the image when needed. The problem is that, with the code I've got, it only works on Firefox, it doesn't work on chrome and opera, while IE seems to not support such a thing at all.

If anyone could suggest me anything, or a different method that would work on all browsers, or at least in chrome, I'd really appreciate it.

Here's my code for the drag and drop:

vb Code:
  1. Public ImageFileStream As FileStream
  2.  
  3. Private Sub PhotoPictureBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PhotoPictureBox.DragEnter
  4.  
  5.         If e.Data.GetDataPresent(DataFormats.FileDrop, False) Then
  6.             Dim strFile() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
  7.             Dim fi As New System.IO.FileInfo(strFile(0))
  8.             If fi.Extension = ".gif" Or fi.Extension = ".bmp" Or fi.Extension = ".jpg" Or fi.Extension = ".jpeg" Or fi.Extension = ".png" Then
  9.                 e.Effect = DragDropEffects.Copy
  10.             End If
  11.         End If
  12.     End Sub
  13.  
  14.  
  15.     Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PhotoPictureBox.DragDrop
  16.  
  17.         Dim s() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
  18.         ImageFileStream = New FileStream(s(0), IO.FileMode.Open)
  19.         Dim bm As New Bitmap(ImageFileStream)
  20.         PhotoPictureBox.SizeMode = PictureBoxSizeMode.Zoom
  21.         PhotoPictureBox.Image = bm
  22.     End Sub

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>