Hier ein kmpl. Beispiel:
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Vom Windows Form Designer generierter Code "
#End Region
Private source As PictureBox = Nothing
Private Sub PictureBox_DragOver(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.DragEventArgs)
e.Effect = DragDropEffects.Move
End Sub
Private Sub PictureBox_DragEnter(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.DragEventArgs)
Dim pb As PictureBox = CType(sender, PictureBox)
Application.DoEvents()
Dim gr As Graphics = pb.CreateGraphics
Dim x As Integer = 10, y As Integer = 10
gr.DrawRectangle(New Pen(Color.White, 1), New Rectangle(0, 0, pb.Width _
- 1, pb.Height - 1))
gr.DrawString("Hierher verschieben..", Me.Font, Brushes.Red, x, y)
End Sub
Private Sub PictureBox_DragLeave(ByVal sender As System.Object, ByVal e As _
EventArgs)
Dim pb As PictureBox = CType(sender, PictureBox)
pb.Refresh()
Application.DoEvents()
End Sub
Private Sub PictureBox_DragDrop(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.DragEventArgs)
Try
Dim pb As PictureBox = CType(sender, PictureBox)
Dim newimg As Image = CType(e.Data.GetData(GetType(Bitmap)), Bitmap)
source.Image = pb.Image
pb.Image = newimg
pb.Size = newimg.Size
Application.DoEvents()
Dim gr As Graphics = pb.CreateGraphics
Dim x As Integer = 0, y As Integer = 0
gr.DrawString("Wurde verschoben..", Me.Font, Brushes.White, x, y)
Application.DoEvents()
Threading.Thread.Sleep(1000)
pb.Refresh()
Application.DoEvents()
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
End Sub
Private Sub PictureBox_MouseMove(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
Dim pb As PictureBox = CType(sender, PictureBox)
Me.source = pb
pb.DoDragDrop(pb.Image, DragDropEffects.Move)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Dim pb As PictureBox = Nothing
Dim img As Image = Nothing
Dim fileName As String = Nothing
Dim x As Integer = 0, y As Integer = 10
For a As Integer = 0 To 3
fileName = IO.Path.Combine(Application.StartupPath, (a + _
1).ToString + ".bmp")
pb = New PictureBox
pb.AllowDrop = True
img = New Bitmap(Image.FromFile(fileName), 200, 200)
pb.Image = img
pb.Size = img.Size
pb.Location = New Point(x, y)
x += pb.Size.Width
Me.SetHandler(pb)
Me.Controls.Add(pb)
Next
Me.Width = x + 20
End Sub
Private Sub SetHandler(ByVal pb As PictureBox)
AddHandler pb.MouseMove, AddressOf PictureBox_MouseMove
AddHandler pb.DragDrop, AddressOf PictureBox_DragDrop
AddHandler pb.DragEnter, AddressOf PictureBox_DragEnter
AddHandler pb.DragOver, AddressOf PictureBox_DragOver
AddHandler pb.DragLeave, AddressOf PictureBox_DragLeave
End Sub
End Class Hatte gerade etwas Langeweile
(Du benötigst hierfür 4 Bilder (jeweils 0, 1, 2, 3.bmp) im Ausführungsordner und eine Form) |