Public Class Form1
Inherits System.Windows.Forms.Form
Dim n As Integer '声明模块级变量
'[出数]按钮的单击事件
Private Sub Btuquestion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btuquestion.Click
Dim nl As New Random
n = nl.Next(0, 10)
Lblresult.Text = "?"
Lblresult.BackColor = System.Drawing.Color.Green '将标签框的背景色设置为绿色
TextBox1.ReadOnly = False '去掉文本框的只读属性
TextBox1.Select()
TextBox1.Text = ""
Lblnn.Text = 0
End Sub
Private Sub Btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnok.Click
If Val(TextBox1.Text = n) Then
Lblresult.Text = "right"
Lblresult.BackColor = System.Drawing.Color.Red
Else
Lblresult.Text = "wrong"
Lblresult.BackColor = System.Drawing.Color.Blue
End If
Lblnn.Text = Lblnn.Text + 1 '显示的次数加1
End Sub
Private Sub Btnanswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnanswer.Click
Lblresult.Text = n
Lblresult.BackColor = System.Drawing.Color.Red
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ThisDay As Integer = Microsoft.VisualBasic.DateAndTime.Day(Now)
TextBox1.ReadOnly = True
Lblnn.Text = 0
Lbldate.Text = Year(Now) & "年" & Month(Now) & "月" & ThisDay & "日"
End Sub
End Class
day函数的特殊性:不能够直接获得!需要处理后获取!
使用Random类生成随机数!