Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

Single Instance Form in a MDI application

0.00/5 (No votes)
1 Oct 2011CPOL 8.3K  
private void OpenForm() where T : Form, new(){ T frm = (T)new List(this.MdiChildren).Find(f => f is T) ?? new T() { MdiParent = this }; frm.Show(); frm.Focus();}and usageOpenForm();
C#
private void OpenForm<T>() where T : Form, new()
{
    T frm = (T)new List<Form>(this.MdiChildren).Find(f => f is T) ?? new T() { MdiParent = this };

    frm.Show();
    frm.Focus();
}

and usage
C#
OpenForm<NewForm>();

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)