Click here to Skip to main content
15,887,315 members
Home / Discussions / C#
   

C#

 
GeneralRe: Use textfile as source for a combo boxes items? Pin
clashie8-Sep-07 17:42
clashie8-Sep-07 17:42 
QuestionMarshalling Pin
aruna_koride8-Sep-07 13:46
aruna_koride8-Sep-07 13:46 
QuestionPropertyGrid Binding in WPF Pin
aruna_koride8-Sep-07 13:38
aruna_koride8-Sep-07 13:38 
QuestionUsing Low Level keyboard hook problem [modified] Pin
kamalesh828-Sep-07 12:03
kamalesh828-Sep-07 12:03 
QuestionSingle instance forms in an MDI app Pin
martin_hughes8-Sep-07 9:20
martin_hughes8-Sep-07 9:20 
AnswerRe: Single instance forms in an MDI app [modified] Pin
Ed.Poore8-Sep-07 12:25
Ed.Poore8-Sep-07 12:25 
GeneralRe: Single instance forms in an MDI app [modified] Pin
martin_hughes8-Sep-07 13:38
martin_hughes8-Sep-07 13:38 
GeneralRe: Single instance forms in an MDI app Pin
Ed.Poore8-Sep-07 13:51
Ed.Poore8-Sep-07 13:51 
martin_hughes wrote:
I guess that the where T : Form limits what can be passed in as

Correct
martin_hughes wrote:
but what's the new() about?

It constrains the types passed in, they must have a default constructor (public ClassName() { }).  Alternatively if you didn't what this you could use:
Activator.CreateInstance<T>(); instead of new T().  If you remove the constraint you'll see the compiler throw an exception because the class may not necessarily implement a default constructor.
martin_hughes wrote:
But doing so looks a bit errrmm inellegant

One answer is to hook into the child form's closing event and remove the entry from there and dispose of it (frees up resources too).
if (!this.SingleInstanceForms.ContainsKey(typeof(T)))
{
    T newForm = new T();
    newForm.MdiParent = this;
    newForm.FormClosing += new FormClosingEventHandler(delegate (object sender, FormClosingEventArgs e)
        {
            Form senderForm = (sender as Form);
            // Tidy up...
            senderForm.Dispose();
            this.SingleInstanceForms.Remove(senderForm.GetType());
        }
    ));
    this.SingleInstanceForms.Add(typeof(T), newForm);
}
...
Now you don't have to check if there's a disposed form there because they are automatically removed from the dictionary (and properly disposed of).



GeneralRe: Single instance forms in an MDI app Pin
martin_hughes8-Sep-07 14:18
martin_hughes8-Sep-07 14:18 
GeneralRe: Single instance forms in an MDI app Pin
Ed.Poore9-Sep-07 0:19
Ed.Poore9-Sep-07 0:19 
GeneralRe: Single instance forms in an MDI app Pin
martin_hughes9-Sep-07 7:36
martin_hughes9-Sep-07 7:36 
GeneralRe: Single instance forms in an MDI app Pin
Ed.Poore9-Sep-07 9:12
Ed.Poore9-Sep-07 9:12 
GeneralRe: Single instance forms in an MDI app Pin
Ed.Poore9-Sep-07 13:39
Ed.Poore9-Sep-07 13:39 
QuestionNeed an Algorithm like 'Word Wrap' in notepad. Pin
hdv2128-Sep-07 6:54
hdv2128-Sep-07 6:54 
AnswerRe: Need an Algorithm like 'Word Wrap' in notepad. Pin
Giorgi Dalakishvili8-Sep-07 7:26
mentorGiorgi Dalakishvili8-Sep-07 7:26 
QuestionConsuming Java Web Service using C# Pin
arctix8-Sep-07 4:48
arctix8-Sep-07 4:48 
AnswerRe: Consuming Java Web Service using C# Pin
Guffa8-Sep-07 4:58
Guffa8-Sep-07 4:58 
QuestionRe: Consuming Java Web Service using C# [modified] Pin
arctix9-Sep-07 2:57
arctix9-Sep-07 2:57 
QuestionGenerics Problem Question Pin
PaulPrice8-Sep-07 4:44
PaulPrice8-Sep-07 4:44 
AnswerRe: Generics Problem Question Pin
Giorgi Dalakishvili8-Sep-07 4:49
mentorGiorgi Dalakishvili8-Sep-07 4:49 
GeneralRe: Generics Problem Question Pin
PaulPrice8-Sep-07 4:58
PaulPrice8-Sep-07 4:58 
GeneralRe: Generics Problem Question Pin
Giorgi Dalakishvili8-Sep-07 5:05
mentorGiorgi Dalakishvili8-Sep-07 5:05 
GeneralRe: Generics Problem Question Pin
PaulPrice8-Sep-07 5:11
PaulPrice8-Sep-07 5:11 
GeneralRe: Generics Problem Question Pin
Giorgi Dalakishvili8-Sep-07 5:18
mentorGiorgi Dalakishvili8-Sep-07 5:18 
QuestionAntivirus question Pin
sajid.salim.khan8-Sep-07 4:20
sajid.salim.khan8-Sep-07 4:20 

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.