Public Class Form1
    Dim r As Integer
    Dim a(3, 3) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        r = PictureBox1.Width \ 3  '格子的宽度
        Dim g As Graphics = PictureBox1.CreateGraphics()
        Dim myPen As New Pen(Color.Red)
        For i = 0 To 3                 '画竖线
            g.DrawLine(myPen, r * i, 0, r * i, r * 3)
        Next
        For i = 0 To 3                 '画横线
            g.DrawLine(myPen, 0, r * i, r * 3, r * i)
        Next
    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        Dim qx , qy As Integer
        qx = e.X \ r
        qy = e.Y \ r
        If a(qx, qy) <> 0 Then         '已经有棋子
            MsgBox("已经有棋子", , "提醒")
            Exit Sub
        End If
        Dim g As Graphics = PictureBox1.CreateGraphics()
        If (Label1.Text <> "下黑色棋") Then
            Dim brush1 As New SolidBrush(Color.White)
            g.FillEllipse(brush1, qx * r, qy * r, r, r)
            a(qx, qy) = 1               '白棋
            Label1.Text = "下黑色棋"
        Else
            Dim brush1 As New SolidBrush(Color.Black)
            g.FillEllipse(brush1, qx * r, qy * r, r, r)
            a(qx, qy) = 2               '黑棋
            Label1.Text = "下白色棋"
        End If
    End Sub
End Class
