Public Class Form4
    Dim ox As Boolean

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Call click_ox(1)
        Call fight()
    End Sub

    Private Sub Label2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label2.Click
        Call click_ox(2)
        Call fight()
    End Sub

    Private Sub Label3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.Click
        Call click_ox(3)
        Call fight()
    End Sub

    Private Sub Label4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label4.Click
        Call click_ox(4)
        Call fight()
    End Sub

    Private Sub Label5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label5.Click
        Call click_ox(5)
        Call fight()
    End Sub

    Private Sub Label6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label6.Click
        Call click_ox(6)
        Call fight()
    End Sub

    Private Sub Label7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label7.Click
        Call click_ox(7)
        Call fight()
    End Sub

    Private Sub Label8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label8.Click
        Call click_ox(8)
        Call fight()
    End Sub

    Private Sub Label9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label9.Click
        Call click_ox(9)
        Call fight()
    End Sub

    Sub click_ox(ByVal a)
        ox = Not ox
        If ox = True Then
            Controls("Label" & a).text = "O"
        Else
            Controls("Label" & a).text = "X"
        End If
    End Sub

    Sub fight()
        If Label1.Text = "O" And Label2.Text = "O" And Label3.Text = "O" Then MsgBox("O贏了")
        If Label4.Text = "O" And Label5.Text = "O" And Label6.Text = "O" Then MsgBox("O贏了")
        If Label7.Text = "O" And Label8.Text = "O" And Label9.Text = "O" Then MsgBox("O贏了")
        If Label1.Text = "O" And Label4.Text = "O" And Label7.Text = "O" Then MsgBox("O贏了")
        If Label2.Text = "O" And Label5.Text = "O" And Label8.Text = "O" Then MsgBox("O贏了")
        If Label3.Text = "O" And Label6.Text = "O" And Label9.Text = "O" Then MsgBox("O贏了")
        If Label1.Text = "O" And Label5.Text = "O" And Label9.Text = "O" Then MsgBox("O贏了")
        If Label3.Text = "O" And Label5.Text = "O" And Label7.Text = "O" Then MsgBox("O贏了")

        If Label1.Text = "X" And Label2.Text = "X" And Label3.Text = "X" Then MsgBox("X贏了")
        If Label4.Text = "X" And Label5.Text = "X" And Label6.Text = "X" Then MsgBox("X贏了")
        If Label7.Text = "X" And Label8.Text = "X" And Label9.Text = "X" Then MsgBox("X贏了")
        If Label1.Text = "X" And Label4.Text = "X" And Label7.Text = "X" Then MsgBox("X贏了")
        If Label2.Text = "X" And Label5.Text = "X" And Label8.Text = "X" Then MsgBox("X贏了")
        If Label3.Text = "X" And Label6.Text = "X" And Label9.Text = "X" Then MsgBox("X贏了")
        If Label1.Text = "X" And Label5.Text = "X" And Label9.Text = "X" Then MsgBox("X贏了")
        If Label3.Text = "X" And Label5.Text = "X" And Label7.Text = "X" Then MsgBox("X贏了")

    End Sub
End Class
