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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
Public Class Form1
Dim isDragging As Boolean = False
Dim CurrentX As Integer, CurrentY As Integer
Dim Bouton(64) As Button
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then
isDragging = True
CurrentX = e.X
CurrentY = e.Y
End If
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If isDragging Then
PictureBox1.Top += (e.Y - CurrentY)
PictureBox1.Left += (e.X - CurrentX)
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
isDragging = False
For i As Integer = 0 To 63
If (((PictureBox1.Location.X + 15) >= Bouton(i).Location.X) And ((PictureBox1.Location.X + 15) <= Bouton(i).Location.X + 30)) And _
(((PictureBox1.Location.Y + 15) >= Bouton(i).Location.Y) And ((PictureBox1.Location.Y + 15) <= Bouton(i).Location.Y + 30)) Then
PictureBox1.Location = Bouton(i).Location
Exit For
End If
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CrééTableau(20, 40)
PictureBox1.Size = New Size(30, 30)
End Sub
Private Sub CrééTableau(ByVal PosX As Integer, ByVal PosY As Integer)
Dim Index As Integer = 0
Dim Ligne(4) As TextBox
'Ligne gauche
Ligne(0) = New TextBox
With Ligne(0)
.Multiline = True
.Size = New Size(2, (30 * 8))
.Location = New Point(PosX, PosY)
.BorderStyle = BorderStyle.FixedSingle
End With
Me.Controls.Add(Ligne(0))
'Ligne droite
Ligne(1) = New TextBox
With Ligne(1)
.Multiline = True
.Size = New Size(2, (30 * 8))
.Location = New Point(PosX + (30 * 8), PosY)
.BorderStyle = BorderStyle.FixedSingle
End With
Me.Controls.Add(Ligne(1))
'Ligne haut
Ligne(2) = New TextBox
With Ligne(2)
.Multiline = True
.Size = New Size((30 * 8), 2)
.Location = New Point(PosX, PosY)
.BorderStyle = BorderStyle.FixedSingle
End With
Me.Controls.Add(Ligne(2))
'Ligne bas
Ligne(3) = New TextBox
With Ligne(3)
.Multiline = True
.Size = New Size((30 * 8) + 2, 2)
.Location = New Point(PosX, PosY + (30 * 8))
.BorderStyle = BorderStyle.FixedSingle
End With
Me.Controls.Add(Ligne(3))
For a As Integer = 0 To 7
For b As Integer = 0 To 7
Bouton(Index) = New Button
With Bouton(Index)
.Size = New Size(30, 30)
.Location = New Point((a * 30) + 2 + PosX, (b * 30) + 2 + PosY)
.FlatAppearance.BorderSize = 0
.FlatStyle = FlatStyle.Flat
End With
Select Case a
Case 0, 2, 4, 6
Select Case b
Case 0, 2, 4, 6
Bouton(Index).BackColor = Color.White
Case 1, 3, 5, 7
Bouton(Index).BackColor = Color.LightGray
End Select
Case 1, 3, 5, 7
Select Case b
Case 0, 2, 4, 6
Bouton(Index).BackColor = Color.LightGray
Case 1, 3, 5, 7
Bouton(Index).BackColor = Color.White
End Select
End Select
Me.Controls.Add(Bouton(Index))
Index += 1
Next
Next
End Sub
End Class |
Partager