Form Load not firing but form appears?

J

jcrouse

I have an odd issue going on with the calling of my forms. I have an
application that has a wizard. The wizard consists of about eight forms that
the user makes choices on. Each form has a "Back" and "Next" button. When
the user selects the "Next" button the form's user choices are saved to
variables and then the form is disposed and the next form called. The
problem is that when debugging I put a stopwatch on a form_load event on one
of the forms but the event never fires, even though the form appears on the
screen. How can this happen? I'm confused. IF it hit the back button the
next is still does the same thing. Even though the back button should also
dispose of the form. If I close the form with the "X" in the title bar then
go back through the wizard a second time, the form_load event fires. It's
almost like the form is already there or something. I have even added a
form.dispose() to the startup form for all of the forms in the wizard just
to try and get rid of them if they somehow already exist. Here is some of my
code:



Sub Main()

Dim frmSC as new frmSaveConfig

... much more code

End Sub



Public Class myForms

Private Shared m_frmSaveConfig As frmSaveConfig

Public Shared Property frmSaveConfig() As frmSaveConfig

Get

Return m_frmSaveConfig

End Get

Set(ByVal Value As frmSaveConfig)

m_frmSaveConfig = Value

End Set

End Property

... many more forms exist here

End Class



This is the code from the btn_Next click event of the calling form:



If frmSC Is Nothing OrElse frmSC.IsDisposed Then

frmSC = New frmSaveConfig

myForms.frmSaveConfig = frmSC

End If

ico.Dispose()

bm.Dispose()

Me.Dispose()

frmSC.ShowDialog()



Thanks,

John
 
H

Herfried K. Wagner [MVP]

* "jcrouse said:
I have an odd issue going on with the calling of my forms. I have an
application that has a wizard. The wizard consists of about eight forms that
the user makes choices on. Each form has a "Back" and "Next" button. When
the user selects the "Next" button the form's user choices are saved to
variables and then the form is disposed and the next form called. The
problem is that when debugging I put a stopwatch on a form_load event on one
of the forms but the event never fires, even though the form appears on the
screen.

Are you sure the event handler is connected to the event properly? Make
sure that there is a 'Handles MyBase.Load' appended to the handling
method's head.
 
J

jcrouse

You mean on the form I'm having problem with, like this:
Private Sub frmSaveConfig_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Thanks,
John
 
C

Cor Ligthert

John,

The form loads only the first time it is loaded, I have the idea you are
looking for the form activate event or what can be as well when that does
not do it either the form visible change event.

I hope this helps?

Cor
 
J

jcrouse

Cor,
I don't understand. First, how can the form possibly be displayed if the
form_load never fires. I put a stopwatch on it and it never fires, but the
form appears. Also, If I dispose of a form should the form_load event fire
the next time I call the form?

Thanks,
John
 
C

Cor Ligthert

John,

I was curious how I would do your problem, so I tried it with this sample.

I do not know if you can use it, the way I do it is called recursive.

It is debuggable however see that the sub is calling itself so that makes
debugging sometimes confusing.

When this does not help, show than some more of your code.

Cor


\\\2 forms with on form1 nothing and on form 2 a label, a textbox and 2
buttons 'in one of the buttons is the dialogresult.cancel property changed
in whatever
'however that is the next button
Private lastform As Integer
Private myformsar As New ArrayList
Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
lastform = 0
Do Until lastform = 7
If lastform = 0 Then
doforms(0)
Else
doforms(lastform - 1)
End If
Loop
MessageBox.Show(DirectCast(myformsar(7), info).text)
Me.Close()
End Sub
Private Sub doforms(ByVal formnumber As Integer)
Dim frm As New Form2
lastform = formnumber
frm.Label1.Text = (formnumber + 1).ToString
If myformsar.Count < formnumber + 1 Then
Dim myinfo As New info
myinfo.formnumber = formnumber
myinfo.text = "Myform" & formnumber.ToString
myformsar.Add(myinfo)
End If
frm.textbox1.Text = DirectCast(myformsar(formnumber), info).text
frm.Label1.Text = formnumber.ToString
If frm.ShowDialog = DialogResult.Cancel Then
frm.Dispose()
Exit Sub
Else
DirectCast(myformsar(formnumber), info).text = frm.textbox1.Text
frm.Dispose()
If lastform <> 7 Then
lastform += 1
doforms(lastform)
Else
Exit Sub
End If
End If
End Sub
End Class
Friend Class info
Friend text As String
Friend formnumber As Integer
End Class
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top