猜数游戏

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类生成随机数!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值