Hi all,
Anyone who's done any UI work in .Net is very familiar with this type of code:
TestForm frm = new TestForm();
frm.ShowDialog();
Earlier today i found myself wishing that a call to show a modal dialog was a little less verbose, more like a static call, and figured out that all i really need, in a simple case, is something like this:
new TestForm().ShowDialog();
Am i missing anything? Could there be any repercussions from this kind of shorthand? E.g. windows messages not handled/routed correctly etc.?
Was working on this when i saw Ray's feedback:
i suppose an even shorter way would be to create a static member withing TestForm that creates an instance of itself and calls ShowDialog internally. So, this code:
public static DialogResult DoModal()
{
return new TestForm().ShowDialog();
}
could be invoked thusly:
TestForm.DoModal();
Is this what you're talking about Ray? It's static, but does it fit the factory paradigm?