一兆韦德 门店级别:用VB做一个计时器

来源:百度文库 编辑:高考问答 时间:2024/04/20 02:56:37
就是想在规定时间内当时间到了自动会弹出来的那种!!请各位帮帮忙,我是VB的初学者,学VB两个星期了
各位帮帮忙了,我的积分不是很多,就送出5个积分了,大家不要闲少就行了!!可以自已规定时间的那种,时间结束时会有提示消息!

可以这样解决你的问题:这时候timer的时间interval是1000

Private Sub Form_Load()
Text2.Text = "10:55:00"//设置你要求的时间
End Sub

Private Sub Timer1_Timer()
Text1.Text = Time
If (Text1.Text = Text2.Text) Then//比较时间
Print "OK"//弹出提示
End If
End Sub

Option Explicit

''使指定窗口总在最前
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H8

Sub SetFormTopmost(TheForm As Form)

SetWindowPos TheForm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOZORDER + SWP_NOMOVE + SWP_NOSIZE

End Sub

Private Sub Command1_Click()
Me.Hide ''设置好以后点击窗体隐藏
End Sub

Private Sub Form_Load()
Me.BorderStyle = 0 ''设置窗体格式
Timer1.Interval = 1000 ''时间间隔1000毫秒,即1秒
Label1.Caption = "设置时间,格式HHMMSS"
Text1.Text = "" ''比如180000

SetFormTopmost Me ''窗体放在最前,即使你做别的工作,它也会显示在最最前面
End Sub

Private Sub Timer1_Timer()

If (Text1.Text = Format(Time, "hhmmss")) Then ''比较时间
Me.Show
End If
End Sub