I use the following codes for showing child form in a MDI parent form. As you know clicking the button will cause a new form to appear. Keep clicking the button and your screen will be filled with blank forms. To stop this from happening, I moved the code that creates the form outside of the button.
Like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Form2 f2 = new Form2();
private void button1_Click(object sender, EventArgs e)
{
f2.MdiParent = this;
f2.Show();
}
But when I close the child form and want to open it again, it won’t let me.
Please help me to solve this.
You need to keep track of the form state so you know you need to create a new one. Like this: