1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| Public Class Form1
Private listpics(20) As PictureBox
Private lastmouselocation(20) As Point
Private listpanels(20) As Panel
Private Sub Init()
Dim leftpic As Integer
Dim toppic As Integer
Dim leftpan As Integer
Dim toppan As Integer
leftpic = 0
toppic = 0
leftpan = 0
toppan = Me.Height \ 2
For iter = 0 To listpics.Length - 1
Dim mypic As New PictureBox
With mypic
.Height = 30
.Width = 30
.BorderStyle = BorderStyle.Fixed3D
.BackColor = Color.DarkBlue
.Location = New Point(leftpic, toppic)
.Tag = iter.ToString
AddHandler mypic.MouseMove, AddressOf mypicMouseMove
AddHandler mypic.MouseDown, AddressOf mypicMouseDown
End With
listpics(iter) = mypic
leftpic += mypic.Width + 3
If leftpic > Me.Width - mypic.Width Then
leftpic = 0
toppic += mypic.Height + 3
End If
Me.Controls.Add(mypic)
Dim mypanel As New Panel
With mypanel
.Height = 30
.Width = 30
.BorderStyle = BorderStyle.Fixed3D
.BackColor = Color.DarkRed
.Location = New Point(leftpan, toppan)
.Tag = iter.ToString
End With
listpanels(iter) = mypanel
leftpan += mypanel.Width + 3
If leftpan > Me.Width - mypanel.Width Then
leftpan = 0
toppan += mypanel.Height + 3
End If
Me.Controls.Add(mypanel)
Next
End Sub
Private Sub mypicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
lastmouselocation(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)) = e.Location
End Sub
Private Sub mypicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim ptpic As New Point
Dim ptpan As New Point
ptpic = e.Location
ptpan = e.Location
If e.Button = Windows.Forms.MouseButtons.Left Then
' ptpic.X = ptpic.X + DirectCast(sender, PictureBox).Left - lastmouselocation.X
ptpic.X = ptpic.X + DirectCast(sender, PictureBox).Left - lastmouselocation(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).X
ptpic.Y = ptpic.Y + DirectCast(sender, PictureBox).Top - lastmouselocation(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).Y
ptpan.X = ptpan.X + listpanels(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).Left - (lastmouselocation(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).X)
ptpan.Y = ptpan.Y + listpanels(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).Top - (lastmouselocation(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).Y)
DirectCast(sender, PictureBox).Location = ptpic
listpanels(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).Location = ptpan
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Init()
End Sub
End Class |
Partager