Von Desktop in Picturebox per Drag&Drop

  • VB.NET

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.

    Von Desktop in Picturebox per Drag&Drop

    Hallo,

    Ich habe eine kleine Frage, nun ich habe eine Form mit einer Picturebox jetzt will ich von meinem Desktop
    eine Bilddatei in die Picturebox ziehen per Drag & Drop
    gibt es da eine Möglichkeit? ich habe nur sachen Gefunden wo man von Picturebox zu Picturebox zieht :)

    Ich hoffe mir kann jemand Helfen habe da Total keinen plan von :)


    Gruß
    Sinep
    PS: Google Spuckt auch nicht viel aus wie gesagt nur von Picturebox zu Picturebox
    Im LoadEvent

    PictureBox1.AllowDrop = True

    Im Code

    VB.NET-Quellcode

    1. Private Sub btnImage_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    2. Dim btnPic As Button = CType(sender, Button)
    3. btnPic.DoDragDrop(btnPic.Image, DragDropEffects.Copy)
    4. End Sub
    5. Private Sub pictureBox_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
    6. If e.Data.GetDataPresent(DataFormats.Bitmap) Then
    7. e.Effect = DragDropEffects.Copy
    8. Else
    9. e.Effect = DragDropEffects.None
    10. End If
    11. End Sub
    12. Private Sub pictureBox_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
    13. Dim picbox As PictureBox = CType(sender, PictureBox)
    14. Dim g As Graphics = picbox.CreateGraphics()
    15. g.DrawImage(CType(e.Data.GetData(DataFormats.Bitmap), Image), New Point(0, 0))
    16. End Sub

    Quelle:
    dotnetcurry.com/ShowArticle.aspx?ID=179
    So, ich habe nun eine Lösung gefunden wie ich Per Drag&Drop etwas in die Form laden kann...

    Edit:
    Nun können alle datein dort reingeladen werden ich wollte aber das nur bilder reingeladen werden können! :)

    VB.NET-Quellcode

    1. If e.Data.GetDataPresent("FileDrop", True) Then
    2. Dim files() As String = DirectCast(e.Data.GetData("FileDrop"), String())
    3. For Each file As String In files
    4. TextBox1.Text = (file)
    5. Next
    6. End If



    Gruß
    Sinep

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Sinep“ ()

    Dann musst Du die Bilder austesten:

    VB.NET-Quellcode

    1. For Each file As String In files
    2. If file.ToLower.EndsWith(".jpg") Then
    3. TextBox1.Text &= (file)
    4. End If
    5. Next
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!