Need help desperately on MDI WinForms for VS2005

G

Guest

I am new to this arena of development although I am hoping that some or most
of my C# web development might carry through here as well.

I have started to create a MDI application. I have the MDIParent form and a
test Childform as well.

Use of the controls seems to be pretty self explainatory.

My current problem appears to be the discovery of how I get my ChildForms to
open inside the MDIParent Form. I have right clicked eveywhere and explored
Tools but have not been able to discover how to accomplish this. Is it true
that you still have to hard-code in the relationship between the two?

Can someone lend me your expertise and thoughts on the subject including any
relevant code or reference to books or websites on the subject?

Thank you.

Tim
 
G

Guest

You need to set the MdiParent property of the child form to the instance of
the parent form you want to contain it.

Ciaran O'Donnell
 
S

Steven Blair

Not sure this will help, but here is some code from a 2003 app:

Inside the Main, after I click a menu option, here is how I open a child
form:

Form f = new frmChild(); //frmChild is just your form name
f.MdiParent = this;
f.Show();

And thats it!

2005 maybe allow an easier way, and thats maybe more what your looking
for.
 
S

Stoitcho Goutsev \(100\)

Tim,

You set child form's MdiParent property with a reference to the MDI parent
and call show on the child form. This will show the child form inside the
MDI parent.
 
G

Guest

Steven,

Thank you for the code snipet. That worked just fine. I was able to
complete the onclick event and wire the interface to the childform.

private void applicationUpdateToolStripMenuItem_Click(object sender,
EventArgs e)
{
Form f = new Form2(); //frmChild is just your form name
f.MdiParent = this;
f.Show();

}

My next question is how do I get the childform to come to the front instead
of behind the parent or should I be closing the parentform all together?

Thanks again for your thoughts.

Tim
 
S

Steven Blair

It should be in the front already.
I assume you have set you main form to be a MDIParent, meaning any forms
opened from the MDIParent would automatically open in front of the
container?
 
G

Guest

Steven,

I did setup the mainform as the MDIParent but when I click on the menu item
the second form opens behind the mainform. I think the problem is that I
have panels setup on the MDIParentForm and they are hiding the requested form.

What I would ideally like to do is to get the ChildForm to open up inside a
panel located on the MDIParent. Is this possible?

If not what I am figuring I have to do is to create the MDIParent with
nothing inside of it so when I make a request for a childForm, there is
nothing in front of it.

Thoughts?

Thanks for helping out. I am reading "Pro .Net 2.0" while learning from you
as well. I look forward to building my first applicaiton.

Thanks again.

Tim
 
S

Steven Blair

In my experience, my Main form (MDIParent) does not have any controls on
it, except a toolbar and pulldown menu.
I see that form as a container for the Child forms, so not sure what
advice I can give you there.

Out of curiosity, why would you want a Child form to opn in a panel?
 
G

Guest

Steven,

Thank you for your thoughts. At least now I know what direction I should be
going.

As to why I would want a childform to open up inside a panel?

Answer:
I was attempting to discover a way I could control where a childform would
open up inside the MDIParent form. My impression was that the childForm
opens inside the MDIParent. Is this incorrect?

Tim
 
S

Steven Blair

The Child form opens inside the Parent, thats correct. The code I
supplied would allow that to happen.
 

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