将按键代码添加到VB.Net

时间:2017-11-10 05:31:33

标签: vb.net

我是vb.net的新手,我正在为我的作业创建一个代码。请帮我添加按键代码:(我创建了界面,它运行完美,没有按键代码,但后来我添加了一个按键代码,错误出来:( 我想要做的就是添加一个按键代码,当我按下回车键时,lblGreet的输出是" Jolly Morning(插入人名)"当我再次按回车时,lblGreet的输出没有该人的名字。

这是我的代码:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    lblGreet.Width = Me.Width
    lblGreet.Top = (Me.Height / 2) - (lblGreet.Height / 2)
    lblGreet.Left = (Me.Width / 2) - (lblGreet.Width / 2)

    lblWelcome.Width = 800
    lblDate.Top = 50
    lblDate.Left = 50

    lblTime.Top = 100
    lblTime.Left = 50

    Timer1.Enabled = True
    Me.Location = New Point(0, 0)
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim hour As Integer = DateTime.Now.Hour
    lblDate.Text = Date.Now.ToLongDateString
    lblTime.Text = Date.Now.ToLongTimeString

    If hour >= 12 And hour < 18 Then
        lblGreet.Text = "Jolly Afternoon!"
    ElseIf hour < 12 And hour >= 0 Then
        lblGreet.Text = "Jolly Morning!"
    ElseIf hour >= 18 And hour <= 24 Then
        lblGreet.Text = "Jolly Evening!"
    End If
End Sub

0 个答案:

没有答案