猜大小 会有提示 代码如下:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim num As Integer = -1, str As String, tsum As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsure.Click
If num = -1 Then
MsgBox("您还没有点击开始!", MsgBoxStyle.Critical, "系统提示")
Exit Sub
End If
If tsum = 0 Then
MsgBox("时间已到,请重新开始!", MsgBoxStyle.OKOnly, "系统提示")
Exit Sub
End If
If txtnum.Text < "0 " Or txtnum.Text > "9999" Then
Labanser.ForeColor = ColorTranslator.FromOle(QBColor(15))
Labanser.Text = "您输入的数字超出了范围!"
txtnum.Text = ""
ElseIf Val(txtnum.Text) > num Then
Labanser.ForeColor = ColorTranslator.FromOle(QBColor(14))
Labanser.Text = "数字" & txtnum.Text & "太大了!"
txtnum.Text = ""
ElseIf Val(txtnum.Text) < num Then
Labanser.ForeColor = ColorTranslator.FromOle(QBColor(10))
Labanser.Text = "数字 " & txtnum.Text & " 太小了!"
txtnum.Text = ""
ElseIf Val(txtnum.Text) = num Then
Labanser.ForeColor = ColorTranslator.FromOle(QBColor(11))
Labanser.Text = "恭喜您猜对了!"
Timer3.Enabled = False
End If
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Labanser.Left > 85 Then
Labanser.Left = Labanser.Left - 3
Else : Labanser.Left = 304
Timer1.Enabled = False
txtnum.Focus()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cai.Left = 144 : cai.Top = 0 : shu.Left = -48 : shu.Top = 96 : zi.Left = 304 : zi.Top = 96
tw1.Enabled = True
tsum = 0
rb1.Checked = True
Timer1.Enabled = False
Timer4.Enabled = True
Labanser.Left = 304 : Labanser.Top = 96
End Sub
Private Sub tw1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tw1.Tick
If cai.Left = 144 And cai.Top < 96 Then
cai.Top = cai.Top + 3
ElseIf cai.Left = 144 And cai.Top = 96 Then
tw1.Enabled = False
tw2.Enabled = True
End If
End Sub
Private Sub tw2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tw2.Tick
If shu.Top = 96 And shu.Left < 144 Then
shu.Left = shu.Left + 6
ElseIf shu.Top = 96 And shu.Left = 144 Then
tw2.Enabled = False
tw3.Enabled = True
End If
End Sub
Private Sub tw3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tw3.Tick
If zi.Top = 96 And zi.Left > 144 Then
zi.Left = zi.Left - 8
ElseIf zi.Left = 144 And zi.Top = 96 Then
tw3.Enabled = False
topen.Enabled = True
topen1.Enabled = True
End If
End Sub
Private Sub topen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles topen.Tick
If cai.Left > 96 And cai.Top = 96 Then
cai.Left = cai.Left - 2
ElseIf cai.Left = 96 And cai.Top = 96 Then
topen.Enabled = False
End If
End Sub
Private Sub topen1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles topen1.Tick
If zi.Top = 96 And zi.Left < 192 Then
zi.Left = zi.Left + 2
ElseIf zi.Left = 192 And zi.Top = 96 Then
topen1.Enabled = False
End If
End Sub
Private Sub btnstar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstar.Click
tw1.Enabled = False : tw2.Enabled = False : tw3.Enabled = False : Timer4.Enabled = False
cai.Visible = False : shu.Visible = False : zi.Visible = False
Timer3.Enabled = True
If rb1.Checked = True Then
tsum = 81
ElseIf rb2.Checked = True Then
tsum = 61
ElseIf rb3.Checked = True Then
tsum = 41
End If
Randomize()
num = Int(Rnd() * 10000)
txtnum.Text = ""
txtnum.Focus()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Label3.Text = TimeOfDay
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
tsum = tsum - 1
Label2.Text = "还剩" & tsum & "秒"
If tsum = 0 Then
Timer3.Enabled = False
MsgBox("时间到!", MsgBoxStyle.OKOnly, "系统提示")
Labanser.ForeColor = ColorTranslator.FromOle(QBColor(0))
Labanser.Text = "正确的数字是:" & num & ""
Timer1.Enabled = True
Label2.Text = ""
Timer3.Enabled = False
End If
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
End
End Sub
Dim x As Integer = 0
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
If topen.Enabled = False And topen1.Enabled = False Then
x = x + 1
End If
If x = 2 Then
cai.Visible = False
shu.Visible = False
zi.Visible = False
x = 0
tw1.Enabled = True
cai.Left = 144 : cai.Top = 0 : shu.Left = -48 : shu.Top = 96 : zi.Left = 304 : zi.Top = 96
cai.Visible = True : shu.Visible = True : zi.Visible = True
End If
End Sub
End Class