Click here to Skip to main content
12,399,625 members (48,491 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.9K views
3 bookmarked
Posted

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

You may also be interested in...

Comments and Discussions

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

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.160721.1 | Last Updated 1 Oct 2011
Article Copyright 2011 by Rafał Klepacz
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid