目前要作若干个倒计时条和顺计时条,逻辑上已经解决,但是将即使结果用timer修改label的caption或者修改textbox的text(还有richtextbox)的方法,在计时的过程中以上控件出现闪烁(richtextbox在调试时不闪,打包后闪)。现采用picturebox的print方法,怪事出现了,顺计时不闪,倒计时闪。有经验者赐教,谢谢。一下是timer时间的代码,精确到毫秒
Private Sub timLess1_Timer()
If tt1 < 10 Then
tt1 = "0" & tt1
End If
If tt1 > 0 Then
tt1 = tt1 - 1
Else
If ss1 > 0 Then
ss1 = ss1 - 1
tt1 = 99
Else
If mm1 > 0 Then
mm1 = mm1 - 1
ss1 = 60
End If
End If
End If
frmDisplay.labTimeless1.CurrentX = 300
frmDisplay.labTimeless1.CurrentY = 300
frmDisplay.labTimeless1.ForeColor = vbRed
frmDisplay.labTimeless1.Cls
frmDisplay.labTimeless1.Print Format(mm1, "00") & ":" & Format(ss1, "00") & "." &Format(tt1, "00")
End Sub
Private Sub timLess1_Timer()
If tt1 < 10 Then
tt1 = "0" & tt1
End If
If tt1 > 0 Then
tt1 = tt1 - 1
Else
If ss1 > 0 Then
ss1 = ss1 - 1
tt1 = 99
Else
If mm1 > 0 Then
mm1 = mm1 - 1
ss1 = 60
End If
End If
End If
frmDisplay.labTimeless1.CurrentX = 300
frmDisplay.labTimeless1.CurrentY = 300
frmDisplay.labTimeless1.ForeColor = vbRed
frmDisplay.labTimeless1.Cls
frmDisplay.labTimeless1.Print Format(mm1, "00") & ":" & Format(ss1, "00") & "." &Format(tt1, "00")
End Sub
labTimeless1.AutoRedraw = True
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
Private hTextDC As Long
Private szTextBuf As StringPrivate Sub Timer1_Timer()
If TT1 < 10 Then
TT1 = "0" & TT1
End If
If TT1 > 0 Then
TT1 = TT1 - 1
Else
If SS1 > 0 Then
SS1 = SS1 - 1
TT1 = 99
Else
If MM1 > 0 Then
MM1 = MM1 - 1
SS1 = 60
End If
End If
End If
szTextBuf = Format(MM1, "00") & ":" & Format(SS1, "00") & "." & Format(TT1, "00") Text1.Enabled = False
'---------------------------
Text1.Enabled = False
hTextDC = GetWindowDC(Text1.hwnd)
SetTextColor hTextDC, vbRed
'优化一下:以上3行可写到 From_Load 事件中
'---------------------------
TextOut hTextDC, 3, 3, szTextBuf, Len(szTextBuf)
End Sub
From_Load打错了,咋不能修改了?
楼主用的是picturebox