65.9K
CodeProject is changing. Read more.
Home

Single Instance Form in a MDI application

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Sep 30, 2011

CPOL
viewsIcon

8381

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();

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
OpenForm<NewForm>();