Controlling form instances question

  • Thread starter Thread starter Philip Tepedino
  • Start date Start date
P

Philip Tepedino

Hi,

I'm writing an application which, when the users clicks a button in
FormA(MDI form), FormB is loaded. I'm using Dim FormB as New FormX (FormB
is then set as a child of FormA)
My problem is that, if the user clicks on that same button again, a second
copy of FormB is loaded. Is there a way I can either close any open
instances of FormB then load a new one, or to just bring whatever FormB is
open to the foreground and reuse it? I don't want to ever have more than one
instance of FormB open.

Also, when making an explorer-like interface... if i want to have many
different "side bars", what is the best way to design it in design view?
I've been trying to make panels and just stack them all on top of each other
then show/hide whichever is selected, but thats turning out to be a big pain
with trying to position controls and work with it in general. Is there a
more elegant solution?

Thanks,

Philip Tepedino
 
You can check to see if there's an active MDI child like so, YOu can use
this to test for the name.

SomeVariable = Me.ActiveMdiChild.Name()

If Me.ActiveMDI.Child.Name = YourFormName

me.ActivemdicChild.close

or



If Not Me.ActiveMdiChild Is Nothing Then

Me.ActiveMdiChild.Close()

End If
 
I can't get that to work.
According to MSDN, the ActiveMdiChild only returns a reference to the
currently active form, so how can I check if any of the active forms is the
one I'm looking for?

Also, any ideas about the explorer-interface question?

Thanks again
 
You can use an array and use the following:

myArray = me.MdiChildren

Then loop through the array and check for the form.
 
well if you dont want the form to make copies of itself u have to declare
the variable outside ... either a form level or project level

Dim myform1 As Mod1 ' where Mod1 is a name of a form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not myform1 Is Nothing Then
myform1.Close()
End If
myform1 = New Mod1()
myform1.MdiParent = Me
myform1.Show()
End Sub

this should work...
 
Back
Top