Opening a child form from another child form

J

John

Hi

I have this sub in a main form;

Sub OpenForm(ByVal x As String)
Select Case x
Case "1"
form1 = New frmClients
form1.TopLevel = False
Me.FormsPanel.Controls.Add(form1)
form1.Show()
form1.BringToFront()
Case "2"
form2 = New frmContacts
form2.TopLevel = False
Me.FormsPanel.Controls.Add(form2)
form2.Show()
form2.BringToFront()
End Select
End Sub

I first call the sub in the main form as OpenForm("1") which creates the
first child form1. Now in form1 I call the same sub as;

dim frm as new frmMain
frm.openform("2")

Now even though the sub is called and code is executed, form2 does not
appear on top as needed. What is wrong and how can I make form2 appear from
within form1? Form1 & form2 are both child forms to the main form which
contains the sub OpenForm.

Thanks

Regards
 
H

Herfried K. Wagner [MVP]

* "John said:
form1 = New frmClients
form1.TopLevel = False
Me.FormsPanel.Controls.Add(form1)
form1.Show()
form1.BringToFront()

Just FMI: Why do you use thiy type of "simulated" MDI application?
It's very limited and unflexible...
 
J

John

It allows more control as there are other controls on the main form and by
opening the forms in a panel I can restrict which area the form occupies,
also in this case the user can see only one form at any time keeping the
relevant bits simple.

Regards
 
D

DRaiko

Hi,

I can not explain the feeling that troubles me, but when i see
dim frm as new frmMain
frm.OpenForm()
something ... yes, troubles me.
I'm not sure, but try to pass a pointer to the same instance of the
main form to the form1 (a kind of Parent pointer) and when calling form2
use the same object instance as you use to call form1:
(sorry, i write smthing like VB6 + c#, i have no experiances in vb7)

' Form1
private MainForm _parent

public property let Parent( MainForm parent)
_parent= parent
end property

.....
_parent.OpenForm( "2") ' instead of:
' dim frm as new frmMain
' frm.openform("2")

And in OpenFoerm() before
form1.Show()
make
form1.Parent = Me ' so that each form created here has a pointer to main

If i am right, then the reason is that the new instance of the main
form you create to call OpenForm() has not enough settings/links
to act as "a good main form". It is not Show()n; it has no window, ...

Regards,
Dima.
 

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