List<form> forms = new List<form>();
private void btnForm1_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1(this);
forms.Add(frm1);
frm1.Show();
}
private void btnForm2_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2(this);
forms.Add(frm2);
frm2.Show();
}
private void CloseForms(String FormText)
{
int index = -1;
for (int i = 0; i <= forms.Count - 1; i++)
{
if (forms[i].Text ==FormText.Trim())
{
index = i;
break;
}
}
if (index != -1)
{
Form form = forms[index];
form.Close();
forms.RemoveAt(index);
}
}
private void btnForm1Close_Click(object sender, EventArgs e)
{
CloseForms("Form1");
}
private void btnForm2Close_Click(object sender, EventArgs e)
{
CloseForms("Form2");
}