multiple childs in MDIParent

  • Thread starter Thread starter Paul Mars
  • Start date Start date
P

Paul Mars

FormParent load opens FormChildA.
FormChildA btn click opens FormChildB.
(FormChildA and FormChildB are both children of FormParent)
(FormChildA and FormChildB are different forms)

Problem: FormChildA btn click can only open one instance for FormChildB. I
need multiple instances of FormChildB.

Any suggestions or ideas please.

tx,
Paul
 
in FormChildA button click:

Dim newFormB as New FormChildB
newFormB.Show

-Rob Teixeira [MVP]
 
your newFormB would then not be a child. It needs to be child of FormParent.

The original FormChildB and FormChildA are both declared in FormParent.
FormChildB is module level Public Shared
 
Dim newFormB as New FormChildB
newFormB.MDIParent = FormParent
newFormB.Show

-Rob Teixeira [MVP]
 
This will not work Rob. If I put this in ChildB, it would not recognize
"FormParent". Also, generally why make a second dim for multiple instances?
My code:
Public Class FormParent

Inherits System.Windows.Forms.Form

Windows Form Designer generated code

Public Shared childBInst As New childB

Private Sub OpenChildA_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OpenChildA.Click

Dim childAInst As New childA

With childAInst

..MdiParent = Me

..Show()

..Text = "1st"

End With

childBInst.MdiParent = Me

End Sub

End Class

-------------------------------------

Public Class childA

Inherits System.Windows.Forms.Form

Windows Form Designer generated code

Private Sub OpenChildB_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OpenChildB.Click

with FormParent.childBInst

..Show()

..Text = "2nd"

End With

End Sub

End Class
 
Paul Mars said:
This will not work Rob. If I put this in ChildB, it would not
recognize "FormParent". Also, generally why make a second dim for
multiple instances? My code:

Of course it doesn't recognize FormParent, but I think it's still the same
MDIParent, so you can also use the same MDIParent:

Dim newFormB as New FormChildB
newFormB.MDIParent = Me.MDIParent
newFormB.Show



--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Paul Mars said:
This will not work Rob. If I put this in ChildB, it would not recognize
"FormParent".

Alright, I'll have to be a little more explicit. I should have typed this in
the first place :-)
The issue is that the MdiParent property needs a reference to the MDI form
class, not the name of the MDI form class. But since formA is already an MDI
child, this is easy.

In the childA button click event handler, type:

Dim formB as New childB
formB.MdiParent = Me.MdiParent
formB.Show
Also, generally why make a second dim for multiple instances?

You don't need a second Dim, but your property is a Shared instance.
You could use:

FormParent.childBInst = New childB
With FormParent.childBInst
.MdiParent = Me.MdiParent
.Show
End With

But the Shared reference will only point to the newest childB instance
anyway.

-Rob Teixeira [MVP]
 
Hi Paul,

In this thread is everytime a new instance of an form created in the
samples.

I showed you withouth doing that. The way I did it was create them shared in
the mdi container.

Keep in mind that what is showed in this thread is a totally different
approache from what I showed. (I showed it you only because you did ask to
make it able to open form3 in form2 by the way, wherein I showed you that
you can show and hide it everywhere)

When you do not take the approach I took, there is in my opinon also no need
to create the form shared in my opinion, however keep than in mind that the
information on the form will also everytime in default new state.

Cor
 
I tried your method before and it did not work for me. May be my fault, I
will try it again.

I will also try Rob's last post.

Except right now my wife said "Beach Time". It is nice out. Thanks for all
your help so far, see ya later this afternoon(hopefully).

Paul
 
Hi Paul,
Got it, thanks. Much better then my Public Shared.

This is the same as what Herfried and I showed you in the other thread,
however you said that did not fit you.

Strange!

Cor
 
Back
Top