-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm2.vb
54 lines (41 loc) · 1.62 KB
/
Form2.vb
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
Public Class Form2
' Array de botones para el tablero
Dim botonesTablero(8, 8) As Button
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
iniciarPartida()
End Sub
Private Sub crearBotonesTablero()
Dim contador As Integer = 1
' recorrido del tableLayoutPanel
For i As Integer = 0 To 8
For j As Integer = 0 To 8
' Se crea un botón nuevo en cada iteración
botonesTablero(i, j) = New Button
botonesTablero(i, j).Width = 99
botonesTablero(i, j).Height = 99
botonesTablero(i, j).Name = "bt" + contador.ToString
botonesTablero(i, j).Text = contador.ToString
' Handler para el boton creado
AddHandler botonesTablero(i, j).Click, AddressOf Button_Click
' Se añade el botón creado al tableLayoutPanel
tlpTablero.Controls.Add(botonesTablero(i, j))
contador += 1
Next
Next
End Sub
Private Sub Button_Click(sender As Object, e As EventArgs)
' Variable para copiar el boton
Dim boton As Button = TryCast(sender, Button)
' lanzar el metodo necesario
boton.Enabled = False
boton.BackColor = Color.Red
MessageBox.Show("Has pulsado el boton " + boton.Text)
End Sub
Private Sub iniciarPartida()
' Inicializar los valore por defecto
' Limpiar el tablero
tlpTablero.Controls.Clear()
' Volver a crear los botones de nuevo
crearBotonesTablero()
End Sub
End Class