Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi everybody

I'm new with programming & VS.Net so i have many many questions...

 

 

I have a MainForm that is "IsMdiContainer=true" and another Form with three buttons, each button opens different forms(lets say form3,form4,form5). when any button is clicked i need to close the form(with the three buttons) and open form3 (or form4/form5).

 

The problem is that when i try to open form3/4/5 ,VS (in my fault) actually

try to open it within the form with the three buttons (althought i close it)

and got an exception ("The form that was specified to be the MdiParent for this form is not an MdiContainer").

 

private void button1_Click(object sender, System.EventArgs e)

{

this.Close();

MainForm s = new MainForm();

s.MdiParent = this.MdiParent;

Form3 InnerWindow = new Form3();

InnerWindow.MdiParent = this;

InnerWindow.Show();

}

 

i looked here but it didn't help me (i'm new with programming......)

 

http://www.xtremedotnettalk.com/showthread.php?t=85215

Posted
an exception ("The form that was specified to be the MdiParent for this form is not an MdiContainer").

 

private void button1_Click(object sender, System.EventArgs e)

{

this.Close();

MainForm s = new MainForm();

s.MdiParent = this.MdiParent;

Form3 InnerWindow = new Form3();

InnerWindow.MdiParent = this;

InnerWindow.Show();

}

 

 

If the line I made bold, is the line of code that throws the exception, you are setting the wrong MdiParent. A few lines above you set s.MdiParent to this.MdiParent. So MainForm s is already a child in another mdi container.

I'm not sure, but I remember from an old VB (vb5 I think) book, that it was not possible to nest mdi containers -> you can't have an mdi container inside another mdi container. I dont know if that restriction still exists but it wouldnt surprise me much.

 

If you dont want to use nested mdi containers, just use InnerWindow.MdiParent = this.MdiParent;

Nothing is as illusive as 'the last bug'.
Posted

private void button1_Click(object sender, System.EventArgs e)

{

this.Close();

MainForm s = new MainForm();

Form3 InnerWindow = new Form3();

InnerWindow.MdiParent = s.MdiParent;

InnerWindow.Show();

}

 

now what happens is that form3 doesn't open inside the container....

 

the same is happens if i write:

 

this.Close();

Form3 InnerWindow = new Form3();

InnerWindow.Show();

 

i can't understand how to set the parent.....(MainForm)

Posted

ok...i got it....

 

(when i'm inside the first child)

 

Form3 InnerWindow = new Form3();

InnerWindow.MdiParent = this.ParentForm;

InnerWindow.Show();

this.Close();

 

and now it works fine.. :rolleyes:

 

10x to all

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...