Create MDI Application In C# dot net Conatin(2 Child Form) open one child form and again open this same child form then same form open 2 times.
Please Give me anser to open one child form at atime in c#
Thanks Regards
Shailaja
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
jingeRank #2,527 · 554 reputationPosted Sep 25, 2009, 11:43 PM EDT
Here is the code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Test1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.IsMdiContainer = true; } //open child 1 private void openChild1ToolStripMenuItem_Click(object sender, EventArgs e) { Form f = new Form(); f.MdiParent = this; f.Show(); } //open child 2 private void openChild2ToolStripMenuItem_Click(object sender, EventArgs e) { Form f = new Form(); f.MdiParent = this; f.Show(); } //close all private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Form f in this.MdiChildren) { if (f != null) { f.Dispose(); } } } } }Let me know if it helps.
jinge
Shailaja Mohite17 reputationPosted Sep 26, 2009, 1:12 AM EDT
But First Child form opened Multiple times
Please tell me How to open first child form at a time
Shailaja Mohite17 reputationPosted Sep 26, 2009, 1:22 AM EDT
I Implement Your Solution But First Child Form Is Open Multiple Times.
Please Tell Me How To Open One Child Form At A Time
jingeRank #2,527 · 554 reputationPosted Sep 26, 2009, 4:01 AM EDT
public Form1() { InitializeComponent(); this.IsMdiContainer = true; } //open child 1 private void openChild1ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.MdiChildren.Length == 0) { Form f = new Form(); f.MdiParent = this; f.Show(); } } //open child 2 private void openChild2ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.MdiChildren.Length == 0) { Form f = new Form(); f.MdiParent = this; f.Show(); } } //close all private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Form f in this.MdiChildren) { if (f != null) { f.Dispose(); } } }