Hallo,
ich habe ein Programm wobei man Bilder aus dem Explorer auf das Formular ziehen kann und angezeigt werden soll.
Das sofortige Anzeigen über DragEnter hat auch funktioniert.
Jetzt wollte ich es aber so machen das wenn ich erst die Maustaste loslasse das Bild angezeigt wird und habe die Methode DragDrop benutzt.
Nur jetzt funktioniert es nicht mehr. sobald ich ein Bild auf das formular ziehe wechselt der Mauszeiger sich in einem Durchfahrtsverbotsschild und es passiert nichts.
Was ist denn bei mir der Fehler? Danke für eine Antwort.
Hier der Code:
Imports System.IO
Imports System.Windows.Forms
Public Class frmBetrachter
#Region "DragDrop"
Private Sub frmBetrachter_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
e.Effect = DragDropEffects.Copy
Dim Dateien() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
Ausgabe(Dateien)
End Sub
#End Region
Sub Ausgabe(ByVal Dateien() As String)
Dim puffer(0) As Byte
Dim g As Graphics = Me.CreateGraphics
Dim s As String = ""
'PICS aus dem Explorer anzeigen
If Dateien.GetUpperBound(0) = 0 Then
End If
Dim fs As New IO.FileStream(Dateien(0), FileMode.Open, FileAccess.Read)
If fs.Name.EndsWith("bmp") _
OrElse fs.Name.EndsWith("jpg") _
OrElse fs.Name.EndsWith("gif") _
OrElse fs.Name.EndsWith("png") Then
Dim imgbild As Image = Image.FromStream(fs)
g.Clear(Color.Black)
g.DrawImage(imgbild, 10, 10)
Me.Text = fs.Name
Else
Refresh()
For Each d As String In Dateien
s &= d & vbCrLf
Next
s &= vbCrLf & vbCrLf _
& "Zum Anzeigen der Dateien ziehe Sie nun eine Datei auf die Flche!"
Dim f As New Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Pixel)
g.DrawString(s, f, Brushes.Beige, 10, 10)
End If
End Sub
Dim ptmaus As Point
Private Sub frmBetrachter_Invalidated(ByVal sender As Object, ByVal e As System.Windows.Forms.InvalidateEventArgs) Handles Me.Invalidated
End Sub
Private Sub frmBetrachter_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Control And e.KeyCode = Keys.V Then
Refresh()
ElseIf e.Control And e.KeyCode = Keys.F Then
Dim meinpea As New PaintEventArgs(Me.CreateGraphics, Me.ClientRectangle)
clipformarteeinfgen(meinpea)
End If
End Sub
Private Sub frmBetrachter_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
ptmaus = e.Location
End Sub
Private Sub tsiFormateAnzeigen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsiFormateAnzeigen.Click
Dim meinpea As New PaintEventArgs(Me.CreateGraphics, Me.ClientRectangle)
clipformarteeinfgen(meinpea)
End Sub
Private Sub clipdateneinfgen(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseDown
Dim s As String = ""
Dim g As Graphics = Me.CreateGraphics
If e.Button = Windows.Forms.MouseButtons.Left Then
With My.Computer.Clipboard
Select Case True
Case .ContainsImage
s = "image"
g.DrawImage(System.Windows.Forms.Clipboard.GetImage, New Point(10, 10))
Case .ContainsText
s = "text"
Dim f As New Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Pixel)
g.DrawString(.GetText, f, Brushes.Black, 10, 10)
Case .ContainsData(DataFormats.FileDrop)
Dim dateien() As String = CType(.GetData(DataFormats.FileDrop), String())
Ausgabe(dateien)
End Select
End With
End If
End Sub
Sub clipformarteeinfgen(ByVal pea As PaintEventArgs)
Dim s As String = ""
Dim formate() As String
formate = My.Computer.Clipboard.GetDataObject.GetFormats()
s = ""
For Each sf As String In formate
s &= sf & vbCrLf
Next
's &=mloc.x &"," mloc.y -'Zur Kontrolle der Mausposition
If s.Length Then
End If
Dim f As New Font("Courier New", 12, FontStyle.Regular)
pea.Graphics.Clear(Color.White)
pea.Graphics.DrawString(s, f, Brushes.Brown, CSng(ptmaus.X), CSng(ptmaus.Y))
End Sub
Private Sub frmBetrachter_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class