I want to simplify some of my codes. So I want to make a function that checks if a certain form is already open. Right now I have a code below each button in my initial form.
private void button_parts_Click(object sender, EventArgs e)
{
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
if (frm is frm_parts) { return; }
}
frm_Teile newForm = new frm_parts();
newForm.Show();
}
Now I would like to have something like:
private void button_parts_Click(object sender, EventArgs e)
{
StartNewForm(frm_parts);
}
private void StartNewForm(Type myForm)
{
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
if (frm is myForm) { return; }
}
myForm newForm = new myForm();
newForm.Show();
}
But I can’t pass the type of the
EDIT function : you can, of course, but I didn’t know how and where to start.
Is there a (more) way to get what I need?
Diego source
share