Forms visibility in .net compared to VB6

E

Ellie

In VB6 you could load a form and if you don't create a separate instance of
the form, it is loaded as a global form using the name of the form. This
makes it visible thoughout the entire application as long as that form is
still loaded. It appears different in .net. If I don't create a specific
instance of a form, it seems to load it but I'm not sure that I can
reference it by the form (class) name. What about the startup form? It seems
that you can reference it by the class name. Any additional insight into the
form behaviour would be greatly appreciated as I have just begun the task of
converting all of our VB6 programs to .net. Thank you.

Ellie
 
M

Miro

I do it this way: - someone gave me this code on this newsgroup a long while
ago and seems to do the trick.
I think this is what you are looking for:

'So I can access the same form from multiple forms:
Public Shared fDummyForm As frmDummyForm = Nothing

and then from the 'button' to call the form.

' If the instance still exists... (ie. it's Not Nothing)
If Not IsNothing(fDummyForm) Then
' and if it hasn't been disposed yet
If Not fDummyForm.IsDisposed Then
' then it must already be instantiated - maybe it's
' minimized or hidden behind other forms ?
fDummyForm.BringToFront() ' Optional
Else
' else it has already been disposed, so you can
' instantiate a new form and show it
fDummyForm = New frmDummyForm
fDummyForm.MdiParent = Me
fDummyForm.WindowState = FormWindowState.Maximized
fDummyForm.Show()
End If
Else
' else the form = nothing, so you can safely
' instantiate a new form and show it
fDummyForm = New frmDummyForm
fDummyForm.MdiParent = Me
fDummyForm.WindowState = FormWindowState.Maximized
fDummyForm.Show()
End If
 
P

Patrice

Starting with 2.0 you also have My.Forms.FormName that AFAIK reproduces the
VB6 behavior...
 

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