提问人:Sofy Mastertech 提问时间:10/23/2023 最后编辑:Mayukh BhattacharyaSofy Mastertech 更新时间:10/23/2023 访问量:51
在VBA中更新用户窗体中的时间时删除闪烁的光标
Removing the blinking cursor when updating time in user form in VBA
问:
我使用用户表单创建了一个日历,并在其中放置了一个使用标签的时间跟踪器,称为使用函数时是否有某种方法可以消除光标闪烁lblCurrentTime
Application.OnTime
以下代码可能是光标闪烁的原因,我想消除这种影响。
Option Explicit
'Set global variable
Dim UpdateTime As Double
Dim LastUpdateTime As Double
Sub StartTimer()
' Set the initial time and schedule the first update
UpdateTime = Now + TimeValue("00:00:01")
LastUpdateTime = Now
Application.OnTime UpdateTime, "UpdateCurrentTime"
End Sub
Sub UpdateCurrentTime()
' Update the label with the current time
frmCalendar.lblCurrentTime.Caption = Format(Now(), "hh:mm AM/PM")
' Calculate the time until the next update
LastUpdateTime = LastUpdateTime + TimeValue("00:00:01")
UpdateTime = LastUpdateTime + TimeValue("00:00:01")
' Schedule the next update
Application.OnTime UpdateTime, "UpdateCurrentTime"
End Sub
Sub StopTimer()
' Clear any scheduled updates
On Error Resume Next
Application.OnTime UpdateTime, "UpdateCurrentTime", , False
On Error GoTo 0
End Sub
答: 暂无答案
评论