ประเด็นคือผมทำการสร้าง Form มาใหม่ 1 Form ชื่อ Form1 แต่พอ Run กลับเป็น Form เปล่าทั้งที่ใน Form ที่ผมสร้างมันก็มี code และพอเข้าไปดูใน Property ตรง start up กลับมีอีก Form ชื่อ XOgame ให้เลือกทั้งๆที่ผมไม่ได้สร้าง แต่พอ Run กลับทำงานได้ทั้งที่ Code ก็เหมือนกัน Code (VB.NET)
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Namespace XOgame
Public Class Form1
Inherits System.Windows.Forms.Form
Private l11 As System.Windows.Forms.Button
Private l12 As System.Windows.Forms.Button
Private l13 As System.Windows.Forms.Button
Private l21 As System.Windows.Forms.Button
Private l22 As System.Windows.Forms.Button
Private l23 As System.Windows.Forms.Button
Private l32 As System.Windows.Forms.Button
Private l31 As System.Windows.Forms.Button
Private l33 As System.Windows.Forms.Button
Private resultLabel As System.Windows.Forms.Label
Private playAgainButton As System.Windows.Forms.Button
Private myLabel As System.Windows.Forms.Label
Private mailLinkLabel As System.Windows.Forms.LinkLabel
Private player1Label As System.Windows.Forms.Label
Private player2Label As System.Windows.Forms.Label
Private components As System.ComponentModel.Container = Nothing
Public Sub New()
InitializeComponent()
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If components IsNot Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.l11 = New System.Windows.Forms.Button()
Me.l12 = New System.Windows.Forms.Button()
Me.l13 = New System.Windows.Forms.Button()
Me.l21 = New System.Windows.Forms.Button()
Me.l22 = New System.Windows.Forms.Button()
Me.l23 = New System.Windows.Forms.Button()
Me.l32 = New System.Windows.Forms.Button()
Me.l31 = New System.Windows.Forms.Button()
Me.l33 = New System.Windows.Forms.Button()
Me.resultLabel = New System.Windows.Forms.Label()
Me.playAgainButton = New System.Windows.Forms.Button()
Me.myLabel = New System.Windows.Forms.Label()
Me.mailLinkLabel = New System.Windows.Forms.LinkLabel()
Me.player1Label = New System.Windows.Forms.Label()
Me.player2Label = New System.Windows.Forms.Label()
Me.SuspendLayout()
Me.l11.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l11.Location = New System.Drawing.Point(39, 8)
Me.l11.Name = "l11"
Me.l11.Size = New System.Drawing.Size(64, 64)
Me.l11.TabIndex = 0
AddHandler Me.l11.Click, New System.EventHandler(AddressOf Me.l11_Click)
Me.l12.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l12.Location = New System.Drawing.Point(111, 8)
Me.l12.Name = "l12"
Me.l12.Size = New System.Drawing.Size(64, 64)
Me.l12.TabIndex = 1
AddHandler Me.l12.Click, New System.EventHandler(AddressOf Me.l12_Click)
Me.l13.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l13.Location = New System.Drawing.Point(183, 8)
Me.l13.Name = "l13"
Me.l13.Size = New System.Drawing.Size(64, 64)
Me.l13.TabIndex = 2
AddHandler Me.l13.Click, New System.EventHandler(AddressOf Me.l13_Click)
Me.l21.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l21.Location = New System.Drawing.Point(39, 79)
Me.l21.Name = "l21"
Me.l21.Size = New System.Drawing.Size(64, 64)
Me.l21.TabIndex = 3
AddHandler Me.l21.Click, New System.EventHandler(AddressOf Me.l21_Click)
Me.l22.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l22.Location = New System.Drawing.Point(111, 79)
Me.l22.Name = "l22"
Me.l22.Size = New System.Drawing.Size(64, 64)
Me.l22.TabIndex = 4
AddHandler Me.l22.Click, New System.EventHandler(AddressOf Me.l22_Click)
Me.l23.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l23.Location = New System.Drawing.Point(183, 79)
Me.l23.Name = "l23"
Me.l23.Size = New System.Drawing.Size(64, 64)
Me.l23.TabIndex = 5
AddHandler Me.l23.Click, New System.EventHandler(AddressOf Me.l23_Click)
Me.l32.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l32.Location = New System.Drawing.Point(111, 152)
Me.l32.Name = "l32"
Me.l32.Size = New System.Drawing.Size(64, 64)
Me.l32.TabIndex = 6
AddHandler Me.l32.Click, New System.EventHandler(AddressOf Me.l32_Click)
Me.l31.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l31.Location = New System.Drawing.Point(39, 152)
Me.l31.Name = "l31"
Me.l31.Size = New System.Drawing.Size(64, 64)
Me.l31.TabIndex = 7
AddHandler Me.l31.Click, New System.EventHandler(AddressOf Me.l31_Click)
Me.l33.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.l33.Location = New System.Drawing.Point(183, 152)
Me.l33.Name = "l33"
Me.l33.Size = New System.Drawing.Size(64, 64)
Me.l33.TabIndex = 8
AddHandler Me.l33.Click, New System.EventHandler(AddressOf Me.l33_Click)
Me.resultLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.resultLabel.Location = New System.Drawing.Point(24, 232)
Me.resultLabel.Name = "resultLabel"
Me.resultLabel.Size = New System.Drawing.Size(248, 48)
Me.resultLabel.TabIndex = 9
Me.resultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.playAgainButton.Location = New System.Drawing.Point(64, 280)
Me.playAgainButton.Name = "playAgainButton"
Me.playAgainButton.Size = New System.Drawing.Size(160, 24)
Me.playAgainButton.TabIndex = 10
Me.playAgainButton.Text = "Next Round"
AddHandler Me.playAgainButton.Click, New System.EventHandler(AddressOf Me.playAgainButton_Click)
Me.myLabel.ForeColor = System.Drawing.Color.Brown
Me.myLabel.Location = New System.Drawing.Point(8, 312)
Me.myLabel.Name = "myLabel"
Me.myLabel.Size = New System.Drawing.Size(280, 40)
Me.myLabel.TabIndex = 11
Me.myLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter
Me.mailLinkLabel.Location = New System.Drawing.Point(46, 352)
Me.mailLinkLabel.Name = "mailLinkLabel"
Me.mailLinkLabel.Size = New System.Drawing.Size(192, 16)
Me.mailLinkLabel.TabIndex = 12
Me.mailLinkLabel.TabStop = True
Me.mailLinkLabel.Text = "www.it-devzone.com"
Me.mailLinkLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter
Me.mailLinkLabel.Visible = False
AddHandler Me.mailLinkLabel.LinkClicked, New System.Windows.Forms.LinkLabelLinkClickedEventHandler(AddressOf Me.mailLinkLabel_LinkClicked)
Me.player1Label.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.player1Label.Location = New System.Drawing.Point(0, 280)
Me.player1Label.Name = "player1Label"
Me.player1Label.Size = New System.Drawing.Size(56, 40)
Me.player1Label.TabIndex = 13
Me.player1Label.TextAlign = System.Drawing.ContentAlignment.TopCenter
Me.player2Label.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CByte(178))
Me.player2Label.Location = New System.Drawing.Point(239, 279)
Me.player2Label.Name = "player2Label"
Me.player2Label.Size = New System.Drawing.Size(56, 40)
Me.player2Label.TabIndex = 14
Me.player2Label.TextAlign = System.Drawing.ContentAlignment.TopCenter
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 374)
Me.Controls.Add(Me.player2Label)
Me.Controls.Add(Me.player1Label)
Me.Controls.Add(Me.myLabel)
Me.Controls.Add(Me.playAgainButton)
Me.Controls.Add(Me.resultLabel)
Me.Controls.Add(Me.l33)
Me.Controls.Add(Me.l31)
Me.Controls.Add(Me.l32)
Me.Controls.Add(Me.l23)
Me.Controls.Add(Me.l22)
Me.Controls.Add(Me.l21)
Me.Controls.Add(Me.l13)
Me.Controls.Add(Me.l12)
Me.Controls.Add(Me.l11)
Me.Controls.Add(Me.mailLinkLabel)
Me.Name = "Form1"
Me.Text = "OX Game V1"
AddHandler Me.Load, New System.EventHandler(AddressOf Me.Form1_Load)
Me.ResumeLayout(False)
End Sub
#End Region
<STAThread()> _
Private Shared Sub Form1()
Application.Run(New Form1())
End Sub
Public player As Integer = 1
Public p1Counter As Integer = 0, p2Counter As Integer = 0
Public Sub CheckIfEnd(ByVal l11 As Button, ByVal l12 As Button, ByVal l13 As Button, ByVal l21 As Button, ByVal l22 As Button, ByVal l23 As Button, _
ByVal l31 As Button, ByVal l32 As Button, ByVal l33 As Button)
If l11.Text = l22.Text AndAlso l22.Text = l33.Text AndAlso l33.Text <> "" Then
DisplayTheWinner()
l11.BackColor = Color.Red
l22.BackColor = Color.Red
l33.BackColor = Color.Red
ElseIf l11.Text = l12.Text AndAlso l12.Text = l13.Text AndAlso l13.Text <> "" Then
DisplayTheWinner()
l11.BackColor = Color.Red
l12.BackColor = Color.Red
l13.BackColor = Color.Red
ElseIf l21.Text = l22.Text AndAlso l22.Text = l23.Text AndAlso l23.Text <> "" Then
DisplayTheWinner()
l21.BackColor = Color.Red
l22.BackColor = Color.Red
l23.BackColor = Color.Red
ElseIf l31.Text = l32.Text AndAlso l32.Text = l33.Text AndAlso l33.Text <> "" Then
DisplayTheWinner()
l31.BackColor = Color.Red
l32.BackColor = Color.Red
l33.BackColor = Color.Red
ElseIf l13.Text = l22.Text AndAlso l22.Text = l31.Text AndAlso l31.Text <> "" Then
DisplayTheWinner()
l13.BackColor = Color.Red
l22.BackColor = Color.Red
l31.BackColor = Color.Red
ElseIf l11.Text = l21.Text AndAlso l21.Text = l31.Text AndAlso l31.Text <> "" Then
DisplayTheWinner()
l11.BackColor = Color.Red
l21.BackColor = Color.Red
l31.BackColor = Color.Red
ElseIf l12.Text = l22.Text AndAlso l22.Text = l32.Text AndAlso l32.Text <> "" Then
DisplayTheWinner()
l12.BackColor = Color.Red
l22.BackColor = Color.Red
l32.BackColor = Color.Red
ElseIf l13.Text = l23.Text AndAlso l23.Text = l33.Text AndAlso l33.Text <> "" Then
DisplayTheWinner()
l13.BackColor = Color.Red
l23.BackColor = Color.Red
l33.BackColor = Color.Red
ElseIf l11.Text <> "" AndAlso l12.Text <> "" AndAlso l13.Text <> "" AndAlso l21.Text <> "" AndAlso l22.Text <> "" AndAlso l23.Text <> "" AndAlso l31.Text <> "" AndAlso l32.Text <> "" AndAlso l33.Text <> "" Then
playAgainButton.Visible = True
resultLabel.Text = "DRAW!!"
DisplayLabel()
End If
End Sub
Public Sub DisplayTheWinner()
If player = 2 Then
player = 1
Else
player = 2
End If
resultLabel.Text = "Player " & player & " wins"
playAgainButton.Visible = True
DisableAll()
DisplayLabel()
playAgainButton.[Select]()
If player = 1 Then
p1Counter += 1
player1Label.Text = "Player (1)" & vbLf & vbLf & " [ " & p1Counter & " ]"
ElseIf player = 2 Then
p2Counter += 1
player2Label.Text = "Player (2)" & vbLf & vbLf & " [ " & p2Counter & " ]"
End If
End Sub
Public Sub SwitchPlayer()
If player = 1 Then
player = 2
ElseIf player = 2 Then
player = 1
End If
resultLabel.Text = "Player " & player & " turn"
CheckIfEnd(l11, l12, l13, l21, l22, l23, _
l31, l32, l33)
End Sub
Public Sub DisableAll()
l11.Enabled = False
l12.Enabled = False
l13.Enabled = False
l21.Enabled = False
l22.Enabled = False
l23.Enabled = False
l31.Enabled = False
l32.Enabled = False
l33.Enabled = False
End Sub
Public Sub Reset()
l11.Enabled = True
l11.BackColor = Color.Empty
l11.Text = ""
l12.Enabled = True
l12.BackColor = Color.Empty
l12.Text = ""
l13.Enabled = True
l13.BackColor = Color.Empty
l13.Text = ""
l21.Enabled = True
l21.BackColor = Color.Empty
l21.Text = ""
l22.Enabled = True
l22.BackColor = Color.Empty
l22.Text = ""
l23.Enabled = True
l23.BackColor = Color.Empty
l23.Text = ""
l31.Enabled = True
l31.BackColor = Color.Empty
l31.Text = ""
l32.Enabled = True
l32.BackColor = Color.Empty
l32.Text = ""
l33.Enabled = True
l33.BackColor = Color.Empty
l33.Text = ""
playAgainButton.Visible = False
resultLabel.Text = "Player " & player & " turn"
myLabel.Text = ""
End Sub
Public Sub DisplayLabel()
myLabel.Text = "Write By jubpas "
mailLinkLabel.Visible = True
End Sub
Private Sub l11_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l11.Text = "O"
Exit Select
Case 2
l11.Text = "X"
Exit Select
End Select
l11.Enabled = False
SwitchPlayer()
End Sub
Private Sub l12_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l12.Text = "O"
Exit Select
Case 2
l12.Text = "X"
Exit Select
End Select
l12.Enabled = False
SwitchPlayer()
End Sub
Private Sub l13_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l13.Text = "O"
Exit Select
Case 2
l13.Text = "X"
Exit Select
End Select
l13.Enabled = False
SwitchPlayer()
End Sub
Private Sub l21_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l21.Text = "O"
Exit Select
Case 2
l21.Text = "X"
Exit Select
End Select
l21.Enabled = False
SwitchPlayer()
End Sub
Private Sub l22_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l22.Text = "O"
Exit Select
Case 2
l22.Text = "X"
Exit Select
End Select
l22.Enabled = False
SwitchPlayer()
End Sub
Private Sub l23_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l23.Text = "O"
Exit Select
Case 2
l23.Text = "X"
Exit Select
End Select
l23.Enabled = False
SwitchPlayer()
End Sub
Private Sub l31_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l31.Text = "O"
Exit Select
Case 2
l31.Text = "X"
Exit Select
End Select
l31.Enabled = False
SwitchPlayer()
End Sub
Private Sub l32_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l32.Text = "O"
Exit Select
Case 2
l32.Text = "X"
Exit Select
End Select
l32.Enabled = False
SwitchPlayer()
End Sub
Private Sub l33_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case player
Case 1
l33.Text = "O"
Exit Select
Case 2
l33.Text = "X"
Exit Select
End Select
l33.Enabled = False
SwitchPlayer()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
playAgainButton.Visible = False
resultLabel.Text = "Player " & player & " turn"
player1Label.Text = "Player (1)" & vbLf & vbLf & " [ " & p1Counter & " ]"
player2Label.Text = "Player (2)" & vbLf & vbLf & " [ " & p2Counter & " ]"
End Sub
Private Sub playAgainButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Reset()
End Sub
Private Sub mailLinkLabel_LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs)
End Sub
End Class
End Namespace