Paul Williams Paul Williams - 1 year ago 48 Question

When does the event 'MyBase.Load' fire?

I'm working with the following bit of code to invoke a dialog.

Using frmSomeForm As New SomeForm()
frmSomeForm.intSomeVariable = 6
End Using

Inside that
is a
event. In this particular case:

Private Sub SomeForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If intSomeVariable <> 0 Then SomeOtherSub()
End Sub

My question is when does the load event fire? Does it fire at the moment the
is invoked or is it fired at the moment of the

Answer Source

The Load event is only raised once you call Show() or ShowDialog(), when the form is about to be shown. Currently your frmSomeForm.intSomeVariable = 6 line will always fire before the Load event.

Answering your comment "Would a Property also work in this case?":

Keep in mind that any code that you put before your Show() or ShowDialog() call will be executed first, even if it's a time consuming one. Code isn't executed asynchronously line-by-line.

For example, this:


would only call frmSomeForm.ShowDialog() after the TimeConsumingMethod() has completed successfully, even if that takes for ever.