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
| Public Class Form4
Private ima As Bitmap
Private listpics As New List(Of PictureBox)
Private lastmouselocation As New List(Of Point)
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 As Integer = 0 To 12
Dim mypic As New PictureBox
With mypic
.Height = 50
.Width = 50
.BorderStyle = BorderStyle.Fixed3D
.BackColor = Color.DarkBlue
.Location = New Point(leftpic, toppic)
.Tag = iter.ToString
listpics.Add(mypic)
AddHandler mypic.MouseMove, AddressOf mypicMouseMove
AddHandler mypic.MouseDown, AddressOf mypicMouseDown
End With
lastmouselocation.Add(New Point)
leftpic += mypic.Width + 3
If leftpic > Me.Width - mypic.Width Then
leftpic = 0
toppic += mypic.Height + 3
End If
Me.Panelgame.Controls.Add(mypic)
mypic.BringToFront()
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(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).X
ptpic.Y = ptpic.Y + DirectCast(sender, PictureBox).Top - lastmouselocation(Convert.ToInt32(DirectCast(sender, PictureBox).Tag)).Y
DirectCast(sender, PictureBox).Location = ptpic
End If
End Sub
Private Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Init()
End Sub
Public Sub New()
' This call is required by the designer.
InitializeComponent()
ima = CType(My.Resources.ResourceManager.GetObject("background"), Bitmap)
Me.Panelgame.BackgroundImage = ima
Me.Panelgame.Size = ima.Size
Me.Panelgame.Location = New Point(0, 0)
' Add any initialization after the InitializeComponent() call.
End Sub
End Class |
Partager