How do I "Fire and forget" a WinForms Form?
Posted
by Neil Barnwell
on Stack Overflow
See other posts from Stack Overflow
or by Neil Barnwell
Published on 2010-03-22T17:14:46Z
Indexed on
2010/03/22
17:21 UTC
Read the original article
Hit count: 312
What's a good technique to create a WinForms Form instance, display it (non-modally) but not have to keep a reference around to it? Normally, as soon as the variable goes out of scope, the form is closed:
var form = new SuperDuperForm();
form.Show();
// Form has probably been closed instantly
I don't want to have to keep track of instances of the form, I want it so that when the user closes the form, it is disposed. One idea I've had that I'm going to implement is a kind of controller that I use to open and display forms, that will keep track of them and monitor when they are closed via callbacks.
I'm just wondering if there are any neat tricks to get away without that. Any ideas?
© Stack Overflow or respective owner