CLRBOY Posted December 15, 2004 Posted December 15, 2004 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 Quote
Wile Posted December 16, 2004 Posted December 16, 2004 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; Quote Nothing is as illusive as 'the last bug'.
CLRBOY Posted December 16, 2004 Author Posted December 16, 2004 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) Quote
Administrators PlausiblyDamp Posted December 16, 2004 Administrators Posted December 16, 2004 MainForm s = new MainForm(); is creating a new instance of the MainForm, not refering to the existing one. This is probably worth a read. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
CLRBOY Posted December 16, 2004 Author Posted December 16, 2004 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.