vb编程代码
Public Class ,,,,
Dim chks(8, 8) As CheckBox
Dim o As Integer
Dim i, j As Integer
Dim P, U As Integer
Dim arr(9, 0) As Object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
o = 0
For i = 0 To 8
For j = 0 To 8
If chks(i, j) Is Nothing Then
chks(i, j) = New CheckBox()
End If
AddHandler chks(i, j).MouseUp, AddressOf Chk_MouseUp
chks(i, j).Appearance = Appearance.Button
chks(i, j).height = 25
chks(i, j).width = 25
chks(i, j).Top = i * 25 + 50
chks(i, j).left = j * 25
chks(i, j).text = ""
chks(i, j).tag = 0
chks(i, j).BackColor = Me.BackColor
chks(i, j).checked = False
chks(i, j).Enabled = True
chks(i, j).Font = New Font("Arial", 14, FontStyle.Bold)
Me.Controls.Add(chks(i, j))
Next
Next
Dim n As Integer = 0
Dim h As Integer = 0
Randomize()
Do While h < 10
P = Math.Floor(Rnd() * 9)
U = Math.Floor(Rnd() * 9)
If chks(P, U).Tag = 0 Then
arr(n, 0) = chks(P, U)
chks(P, U).Tag = 1
h = h + 1
n += 1
End If
Loop
Timer1.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub
Private Sub Chk_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs)
Dim chk As CheckBox = CType(sender, CheckBox)
Dim m As Integer
If chk.Tag = 1 Then
For m = 0 To 9
arr(m, 0).BackColor = Color.Blue
Next
MsgBox("over ")
End
End If
Call autoopen(chk)
End Sub
Sub autoopen(ByVal chk As CheckBox)
Dim row As Integer = chk.Top / 25
Dim col As Integer = chk.Left / 25
Dim i, j As Integer
Dim sum As Integer = 0
For i = row - 1 To row + 1
For j = col - 1 To col + 1
If (i >= 0) And (i < 9) And (j >= 0) And (j < 9) Then
sum += chks(i, j).Tag
End If
Next
Next
chk.Text = sum
chk.Enabled = False
If sum = 0 Then
For i = row - 1 To row + 1
For j = row - 1 To row + 1
If (i >= 1) And (i <= 8) And (j >= 1) And (j <= 8)
Then
If chks(i, j).Text = "" Then
Call autoopen(chks(i, j))
End If
End If
Next
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
o = o + 1
TextBox1.Text = o
End Sub
Private Sub Button1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles
Button1.MouseDoubleClick
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class