用VB怎么在text框中显示系统当前时间并运行时自动刷新时间

用VB怎么在text框中显示系统当前时间并运行时自动刷新时间?
请以text4为例

用VB的Timer控件的Timer事件可随时更新TextBox文本框中显示的当前时间。

Timer 控件,通过引发 Timer 事件,Timer 控件可以有规律地隔一段时间执行一次代码。

Timer 事件,在一个 Timer 控件的预定的时间间隔过去之后发生。该间隔的频率储存于该控件的
Interval 属性中,它以千分之一秒为单位指定时间的长度。

Private Sub Form_Load()
    Timer1.Interval = 500
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
   If Text1.Text <> CStr(Time) Then
      Text1.Text = Time
   End If
End Sub

 

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-12
需要一个timer控件
private sub form_load()
timer1.enabled=true
timer1.interval=1000
end sub
private sub timer1_timer()
text4.text=Time
end sub追问

我要在按Command1的时候显示当前系统的年月日
年月日我已经搞掂 就是时间搞不掂

追答

private sub command1_click()
text4.text=Time
end sub

追问

试过了 时间能显示 但是不会刷新

追答

你说清楚嘛。。。
private sub timer1_timer()
text4.text=Time
end sub
private sub command1_click()
text4.text=Time
timer1.enabled=true
timer1.interval=1000
end sub
需要你创建一个timer控件

本回答被提问者采纳
相似回答