I searched google and I think I have solved the issue.
Again, if someone could quickly skim over my example and lemmi know if it is
the "correct" way of doing things.
It works, but again - is it the right way - or have I not thought of
something down the road.
So from what I can understand...If i want ever one instance of a form, - and
that form can be called from any child form,
any showmodal form, basically from anywhere in the whole project,
I must declare it as a public shared form, and then access it this way
throught the whole project.
If someone can give me a tip or 2 that I missed or am missing or will run
into.
Otherwise all works great so far. :-) ( "so far" is the key word )
Looking at this now, I guess I should be putting a "form.dispose() " or
something somehwere anytime any of these forms are closed so I dont have a
zillion forms in memory ?
Thanks,
Miro
==== code example
Say you have a Parent Form frmMainForm , that calls a Modal Window,
Or the Parent form Calls a Child form ( with mdiparent = (me) ' where "me"
is the parent window )
and every form you only want to ever open 1 instance of.
So what I do now is that I create a
Public Shared fBla as frmFormBla()
for all my forms that I want to only create 1 instance of. I create these
public forms in the frmMainForm code.
Then to Call a form I do this:
If Not IsNothing(fBla) Then
' and if it hasn't been disposed yet
If Not fBla.IsDisposed Then
fBla.BringToFront()
Else
' else it has already been disposed, so you can
' instantiate a new form and show it
fBla = New frmHome()
fBla.MdiParent = Me
fBla.WindowState = FormWindowState.Maximized
fBla.Show()
End If
Else
' else the form = nothing, so you can safely
' instantiate a new form and show it
fBla = New frmHome()
fBla.MdiParent = Me
fBla.WindowState = FormWindowState.Maximized
fBla.Show()
End If
now lets say...fBla has a button that is to open another form that is to be
a child window of the Main Form - and I only ever want it to ever have one
instance of it opend.
at this point I have to go thru and Public Share that new form.
Public Shared fNew as frmNew
then to call it from fBla in the command button i do this:
-Keep in mind this would be again simillar to the code above so only one
instance of it is ever shown. So i would be checking the disposed and
stuff. -simplified it down for email sake.
frmMainForm.fNew = New frmNew
frmMainForm.fNew.MdiParent = frmMainForm
frmMainForm.fNew.WindowState = FormWindowState.Maximized
frmMainForm.fNew.Show()
==== end