Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Single Instance Form in a MDI application

, 1 Oct 2011 CPOL
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... Pinmemberwmjordan1-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.141223.1 | Last Updated 1 Oct 2011
Article Copyright 2011 by Rafał Klepacz
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid