murtazamzk 26 Light Poster

Here is an amazing program to create a tic-tac-toe game in vb.net.First of all in design view place 9 buttons.Then apply the code below.


Public Class Form1
Dim test As Boolean
Dim c1 As Boolean


Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click, b2.Click, b3.Click, b4.Click, b5.Click, b6.Click, b7.Click, b8.Click, b9.Click
If (sender.text = "") Then
test = Not test
If (test = True) Then
sender.text = "0"
Else
sender.text = "X"
End If
End If

If (b1.Text = "X" And b2.Text = "X" And b3.Text = "X") Then
MsgBox("player 2 won")
End If
If (b4.Text = "X" And b5.Text = "X" And b6.Text = "X") Then
MsgBox("player 2 won")
End If
If (b7.Text = "X" And b8.Text = "X" And b9.Text = "X") Then
MsgBox("player 2 won")
End If
If (b1.Text = "X" And b5.Text = "X" And b9.Text = "X") Then
MsgBox("player 2 won")
End If
If (b3.Text = "X" And b5.Text = "X" And b7.Text = "X") Then
MsgBox("player 2 won")
End If
If (b1.Text = "X" And b4.Text = "X" And b7.Text = "X") Then
MsgBox("player 2 won")
End If
If (b2.Text = "X" And b5.Text = "X" And b8.Text = "X") Then
MsgBox("player 2 won")
End If
If (b3.Text = "X" And b6.Text = "X" And b9.Text = "X") Then
MsgBox("player 2 won")
End If


If (b1.Text = "0" And b2.Text = "0" And b3.Text = "0") Then
MsgBox("player 1 won")
End If
If (b4.Text = "0" And b5.Text = "0" And b6.Text = "0") Then
MsgBox("player 1 won")
End If
If (b7.Text = "0" And b8.Text = "0" And b9.Text = "0") Then
MsgBox("player 1 won")
End If
If (b1.Text = "0" And b5.Text = "0" And b9.Text = "0") Then
MsgBox("player 1 won")
End If
If (b3.Text = "0" And b5.Text = "0" And b7.Text = "0") Then
MsgBox("player 1 won")
End If
If (b1.Text = "0" And b4.Text = "0" And b7.Text = "0") Then
MsgBox("player 1 won")
End If
If (b2.Text = "0" And b5.Text = "0" And b8.Text = "0") Then
MsgBox("player 1 won")
End If
If (b3.Text = "0" And b6.Text = "0" And b9.Text = "0") Then
MsgBox("player 1 won")
End If
End Sub
End Class