在form中可以使用Timer control,並有Timer_Timer() event會產生,我想做一個Class,希望在裡面也有相同功能,我試過下面方法但是不行,
Dim Timer1 As Timer
Private Sub Class_Initialize()
Timer1.Enabled = True ' error
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
....
End Sub
我也試過開一個form,裡面放一個Timer,class裡面用Set Timer1=form.Timer1,可是Timer event不會trigger class裡的Timer1_Timer()...
Dim Timer1 As Timer
Private Sub Class_Initialize()
Timer1.Enabled = True ' error
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
....
End Sub
我也試過開一個form,裡面放一個Timer,class裡面用Set Timer1=form.Timer1,可是Timer event不會trigger class裡的Timer1_Timer()...
文章標籤
全站熱搜

Try API Function SetTimer,KillTimer.
我查了一下Windows API,這兩個function宣告如下: Declare Function SetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" Alias "KillTimer" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long Windows API我沒用過,不過看起來好像都要是一個Window才可以用這兩個API吧!?(hWnd參數)
If you don't want to apply it to a window, you can simply pass 0& to hwnd. uElapse is the intervals of your timer. lpTimerFunc is the address of your callBace function(TimerProc). Thus, if you don't want it run,pass the return value of settimer to the secend parameter of killtimer of kill it. Remember, put the callback function in your base Moudle.