我在vb中的项目的每个Windows窗体上都有一个计时器。网名为“定时器”,它的工作原理 我有一个使用计时器的成功代码,但我认为最好避免每种形式的计时器事件(刻度)中的所有例程和重复代码
如何将计时器属性传递给模块中的Function 这是我用我的表格编写的基本代码
Private Sub timer1_tick (ByVal Sender As Object , ByVal e As EventArgs) Handles Timer1.Tick
Static Second As Integer
Second +=1
If second >= 4 Then
Timer1.Stop()
Lbl_Save.Visible = False
Second = 1
End If
End sub
Private Sub btn_Save_Click(ByVal Sender As Object , ByVal e As EventArgs) Handles btn_Save. Click
Timer1.Interval = 300
Timer1.Start()
End Sub
============================
我在(Setting_Module)出错提示中编写的过程
Public Sub Get_Timer(ByRef form_Name As Form)
Static Second As Integer
Second +=1
If second >= 4 Then
formName.Controls("Timer1").Stop() Error
formName.Controls(" Lbl_Save"). Visible = False
Second = 1
End If
End Sub
编译器给我一个错误,因为它无法接受(property:Stop)
任何人都有一个更好的主意,我将非常感谢他
答案 0 :(得分:0)
您应该使用Microsoft的Reactive Framework(又名Rx)-NuGet System.Reactive.Windows.Forms
并添加using System.Reactive.Linq;
-然后您可以执行以下操作:
Private Sub btn_Save_Click(ByVal Sender As Object, ByVal e As EventArgs) Handles btn_Save.Click
Lbl_Save.Visible = True
Observable.
Timer(TimeSpan.FromSeconds(4.0)).
ObserveOn(Me).
Subscribe(Sub(x) Lbl_Save.Visible = False)
End Sub
那么您根本就不会在乎计时器。