Could someone tell me how to include a timer inside of a class? I was trying to set up a panel class that has some generic information in it to be included in many of the form windows included in a bigger project. It would also have some other information of course. But the idea was to create an instance of this class in each form that I wanted the panel to be displayed in. I was hoping not to have to also add a timer control at design time to each form.
So, in the form, I would include this
Private pnl As New pnlGeneric(Me)
Everything else, including a timer.tick event to update the panel, is handled by the pnlGeneric class.
Here was my first attempt at including the timer :
Public Class pnlGeneric
Private tdPanel As New StatusBarPanel
Private tdBar As New StatusBar
Private WithEvents tdTimer As Timer
Sub New(ByVal cForm As Windows.Forms.Form)
tdPanel.Text = DateTime.Now.ToString("M/d/yyyy hh:mm:ss tt")
tdPanel.AutoSize = StatusBarPanelAutoSize.Contents
tdBar.ShowPanels = True
tdBar.Panels.Add(tdPanel)
tdTimer.Interval = 500
tdTimer.Enabled = True
cForm.Controls.Add(tdBar)
End Sub
Sub update(ByVal sender As Object, ByVal e As System.EventArgs) Handles tdTimer.Tick
tdPanel.Text = DateTime.Now.ToString("M/d/yyyy hh:mm:ss tt")
End Sub
End Class