Click here to Skip to main content
11,482,402 members (71,387 online)
Click here to Skip to main content

Tagged as

Single Instance Form in a MDI application

, 1 Oct 2011 CPOL 2.8K 3
Rate this:
Please Sign up or sign in to vote.
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>();

License

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

Share

About the Author

Rafał Klepacz
Software Developer
Poland Poland
No Biography provided
Follow on   Twitter

Comments and Discussions

 
GeneralThis solution is neat. Maybe it is even more useful to retur... Pin
wmjordan1-Oct-11 20:13
memberwmjordan1-Oct-11 20:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 1 Oct 2011
Article Copyright 2011 by Rafał Klepacz
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid