VB中,求一个程序。

要求:(1):在窗体上添加2个定时器Tmr1和Tmr2,Tmr1用于显示系统时间,时间间隔为1秒;tMr2用于判断闹钟时间,时间间隔为0.5秒,Tmr2设置为不可用。2个标签Lbl1和Lbl2,标签Lbl1用于显示时间,设置LBl1的Font属性为:宋体,粗体,二号,背景白色,文字居中对齐,固定边框,标签LBl2的标题为“闹钟时间:”;1个文本框Text1,其内容为空。(2)程序运行时,标签Lbl1中显示系统当前时间,在文本框输入闹钟时间并按回车键后,启动判断闹钟时间的定时器Tmr2,如果Lbl1显示的时间超过闹钟时间,则标签Lbl1的背景色按红白两色交替变换。

Private Sub Form_Load()
Tmr1.Interval = 1000
Tmr1.Enabled = True
Tmr2.Interval = 500
Tmr2.Enabled = False
With Lbl1
.FontName = "宋体"
.FontBold = True
.FontSize = 21.75 '字号=二号
.BackColor = vbWhite
.Alignment = vbCenter
.BorderStyle = 1
End With
Lbl2.Caption = "闹钟时间:"
Text1.Text = ""
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then '如果按了回车
Tmr2.Enabled = True
Lbl2.Caption = "闹钟时间:" & Text1.Text
End If
End Sub

Private Sub Tmr1_Timer()
Lbl1.Caption = Format(Time, "Long Time")
End Sub

Private Sub Tmr2_Timer()
Dim t As Date
Static c As Boolean
t = CDate(Text1.Text)
If t < Time Then
c = Not c
If c Then Lbl1.BackColor = vbRed Else Lbl1.BackColor = vbWhite
End If
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-25
目测楼上的代码是很完整了
相似回答