what handle do i put on a sub so that it gets called when a form is completely finished loading and all its components are initialized?
Printable View
what handle do i put on a sub so that it gets called when a form is completely finished loading and all its components are initialized?
You can use the Activate(d) event but it will fire also if the form comes back into focus from another app or form. To make it only fire once wrap a flag check around it:
VB Code:
Static HasRan As Boolean=False If Not HasRan Then 'put code here HasRan=True End If
can you have a sub that executes every time the form loads, without being called by an event, as if it were a console application, for example?
The only thing outside of an event would be the constructor. Why?
what if, for example you have a textbox that you want to display the time the application started.
where would you set textbox.text = Now().tostring() ???
if you do it in the form designer generated constructor of the textbox, then you can't use the design mode of the form anymore, because vb can't interpret the expression now() at design time and you get an error.
You could use the Load event for that. You could also put it in the constructor after the line that reads: 'Add any initialization after the InitializeComponent() call
ALso if there are any parameters that you want to pass in then you would Overload the constructor to keep the designer working:
Public Sub New(something As String)
Me.New()
'do something with something here
End Sub