vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevAniGif - als kostenlose Vollversion auf unserer vb@rchiv CD Vol.5  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück
Rubrik:    |   VB-Versionen: VB2005, VB2008, VB201001.11.11
Bilder Drag & Drop vom Explorer in eine PictureBox

Dieser Tipp zeigt, wie man eine Bilddatei via Drag & Drop aus dem Windows Explorer in einer PictureBox innerhalb der eigenen Anwendung anzeigen kann.

Autor:  Dieter OtterBewertung:     [ Jetzt bewerten ]Views:  1.728 
http://www.tools4vb.de/System:  WinXP, Win7, Win8, Win10, Win11 Beispielprojekt 

Diesmal zeigen wir Ihnen, wie sich eine Bilddatei via Drag & Drop aus dem Windows Explorer in einer PictureBox anzeigen lässt.

Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
 
  ' Drop Aktion zulassen
  PictureBox1.AllowDrop = True
End Sub
Private Sub PictureBox1_DragEnter(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
 
  ' Prüfen, ob eine FileDrop-Operation vorliegt
  If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
    e.Effect = DragDropEffects.Copy
  End If
End Sub
Private Sub PictureBox1_DragDrop(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
 
  ' ausgewählte Datei in der PictureBox anzeigen
  Dim sFile As String = e.Data.GetData(DataFormats.FileDrop)(0)
  Try
    PictureBox1.Image = Image.FromFile(sFile)
  Catch ex As Exception
    e.Effect = DragDropEffects.None
    MsgBox("Das Bild kann nicht angezeigt werden!" & vbCrLf & vbCrLf & _
      "Fehlermeldung" & vbCrLf & ex.Message, MsgBoxStyle.Exclamation)
  End Try
End Sub