主题:VB 计分器键盘輸入问题
最近正在学习VB,想把以下这个计分器 改为或增加键盘输入控制各个按键,在此向各位请教,谢谢!
Friend Class Form1
Inherits System.Windows.Forms.Form
Dim a As Short
Dim b As Short
Dim minuteVar As Short
Dim secondVar As Short
Dim c As Boolean
Dim d As Boolean
Private Sub Co1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Co1.Click
If Text2.Text <> "" And Text3.Text <> "" Then
Timer1.Enabled = True
Com1.Enabled = True
Com2.Enabled = True
Com3.Enabled = True
Com4.Enabled = True
Com5.Enabled = True
Com6.Enabled = True
Co2.Enabled = True
Label3.Text = Text2.Text
Label4.Text = Text3.Text
Text2.Visible = False
Text3.Visible = False
If d = True Then
If c = False Then
Label5.Text = "第一节"
Else
Label5.Text = "加时赛"
End If
End If
Else
MsgBox("请输入比赛球队名称!")
End If
End Sub
Private Sub Co2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Co2.Click
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
Co1.Text = "继续"
End Sub
Private Sub Co3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Co3.Click
minuteVar = 0
secondVar = 0
FormatTimer()
Co1.Enabled = True
c = True
d = False
End Sub
Private Sub Com1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com1.Click
a = a + 1
Label1.Text = CStr(a)
End Sub
Private Sub Com2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com2.Click
a = a + 2
Label1.Text = CStr(a)
End Sub
Private Sub Com3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com3.Click
a = a + 3
Label1.Text = CStr(a)
End Sub
Private Sub Com4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com4.Click
b = b + 1
Label2.Text = CStr(b)
End Sub
Private Sub Com5_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com5.Click
b = b + 2
Label2.Text = CStr(b)
End Sub
Private Sub Com6_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com6.Click
b = b + 3
Label2.Text = CStr(b)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
minuteVar = 0
secondVar = 0
FormatTimer()
c = False
d = False
End Sub
Private Sub FormatTimer()
Dim chh As String
Dim chm As String
Dim chs As String
Dim cht As String
chm = VB6.Format(minuteVar, "00")
chs = VB6.Format(secondVar, "00")
cht = chm & ":" & chs
Text1.Text = cht
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
FormatTimer()
If minuteVar = 2 And secondVar = 0 Then
Timer1.Enabled = False
End If
If secondVar = 59 Then
minuteVar = minuteVar + 1
secondVar = 0
Else
secondVar = secondVar + 1
End If
If minuteVar = 1 And secondVar = 1 Then
Label5.Text = "第二节"
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
ElseIf minuteVar = 2 And secondVar = 1 Then
Label5.Text = "第三节"
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
ElseIf minuteVar = 3 Then
If Label1.Text = Label2.Text Then
Label5.Text = "加时赛"
Timer1.Enabled = False
Co2.Enabled = False
Co1.Enabled = False
Co3.Visible = True
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
d = True
Else
Label5.Text = "比赛结束"
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
Co2.Enabled = False
End If
End If
End Sub
End Class
Friend Class Form1
Inherits System.Windows.Forms.Form
Dim a As Short
Dim b As Short
Dim minuteVar As Short
Dim secondVar As Short
Dim c As Boolean
Dim d As Boolean
Private Sub Co1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Co1.Click
If Text2.Text <> "" And Text3.Text <> "" Then
Timer1.Enabled = True
Com1.Enabled = True
Com2.Enabled = True
Com3.Enabled = True
Com4.Enabled = True
Com5.Enabled = True
Com6.Enabled = True
Co2.Enabled = True
Label3.Text = Text2.Text
Label4.Text = Text3.Text
Text2.Visible = False
Text3.Visible = False
If d = True Then
If c = False Then
Label5.Text = "第一节"
Else
Label5.Text = "加时赛"
End If
End If
Else
MsgBox("请输入比赛球队名称!")
End If
End Sub
Private Sub Co2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Co2.Click
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
Co1.Text = "继续"
End Sub
Private Sub Co3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Co3.Click
minuteVar = 0
secondVar = 0
FormatTimer()
Co1.Enabled = True
c = True
d = False
End Sub
Private Sub Com1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com1.Click
a = a + 1
Label1.Text = CStr(a)
End Sub
Private Sub Com2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com2.Click
a = a + 2
Label1.Text = CStr(a)
End Sub
Private Sub Com3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com3.Click
a = a + 3
Label1.Text = CStr(a)
End Sub
Private Sub Com4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com4.Click
b = b + 1
Label2.Text = CStr(b)
End Sub
Private Sub Com5_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com5.Click
b = b + 2
Label2.Text = CStr(b)
End Sub
Private Sub Com6_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Com6.Click
b = b + 3
Label2.Text = CStr(b)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
minuteVar = 0
secondVar = 0
FormatTimer()
c = False
d = False
End Sub
Private Sub FormatTimer()
Dim chh As String
Dim chm As String
Dim chs As String
Dim cht As String
chm = VB6.Format(minuteVar, "00")
chs = VB6.Format(secondVar, "00")
cht = chm & ":" & chs
Text1.Text = cht
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
FormatTimer()
If minuteVar = 2 And secondVar = 0 Then
Timer1.Enabled = False
End If
If secondVar = 59 Then
minuteVar = minuteVar + 1
secondVar = 0
Else
secondVar = secondVar + 1
End If
If minuteVar = 1 And secondVar = 1 Then
Label5.Text = "第二节"
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
ElseIf minuteVar = 2 And secondVar = 1 Then
Label5.Text = "第三节"
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
ElseIf minuteVar = 3 Then
If Label1.Text = Label2.Text Then
Label5.Text = "加时赛"
Timer1.Enabled = False
Co2.Enabled = False
Co1.Enabled = False
Co3.Visible = True
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
d = True
Else
Label5.Text = "比赛结束"
Timer1.Enabled = False
Com1.Enabled = False
Com2.Enabled = False
Com3.Enabled = False
Com4.Enabled = False
Com5.Enabled = False
Com6.Enabled = False
Co2.Enabled = False
End If
End If
End Sub
End Class