デフォルト(設計)でタイマーが有効になっていますが、フォームに送信されたいくつかの引数に基づいて、form_loadでタイマーを無効にします。
私は非常に奇妙なシナリオに直面しています。Timer_Tick イベントは、form_load が起動される前でも起動されることがあります。これは、たとえば、アプリケーションが 20 分間最小化されている場合に発生し、アプリケーションを開いて、特に遅いシステムで新しいフォームを開こうとします。 .
次のようにコードします。
'=============== Code of the form with Timer
Public Sub OpenForm(SomeParams)
'Set Form Properties
Me.Show() 'Here the event Form_Load fired
End Sub
Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Some Code ...
Timer1.Enabled = False/ True 'Based True or false based on parameters
'Code ...
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
'Code here
'The code raise error if form load is not fired, because need info from params ...
End Sub
'=============== Code in the calling form (MainForm)
'Calling the Form
dim obj As new Form1 'I think form this line the Timer1_Tick Fired, before load
obj.OpenForm(Params)
例外が発生すると、処理された例外を閉じてフォームを再度開こうとすると、Timer1 が無効になっているフォームが開きます。
デフォルトでタイマーを無効にしてから、パラメータに基づいて有効にするだけですが、Timer1_Tick が OpenForm Sub および Form1_Load Sub の前に発生する理由を知りたいです!! ?
お時間をいただきありがとうございました。サメ