Re: Closing down a hierarchy of modal windows nicely
- From: "Dave Sexton" <dave@jwa[remove.this]online.com>
- Date: Wed, 22 Nov 2006 00:25:02 -0500
Hi Michael,
The Form class has an Owner property. When the Form is a child to
another Form, the Owner property is set, but in the context of "Owner"
code, the simplest way to find that child Form, which needs to be closed,
is to assign the reference to a field when the child is constructed.
There is no "duplication".
I'm not really sure how you consider that not a duplication. You are
storing in a variable that mirrors what the form stores already. The
reference is in 2 places. That is a duplication.
Yes, the variable stores a reference to a child Form which can be found also
by iterating over a collection supplied by the Form itself. You're thinking
much more dynamically about this than I. There is no duplication in storing
a reference that you've already created, which is how I see it:
private Form theReference;
....
theReference = new Form();
theReference.ShowDialog(this);
....
theReference.Close();
No duplication here, from my POV, since the reference was created anyway.
If the OP indicates that each Form may have multiple children then your
solution will probably be better, but that definitely wasn't the case, so
having a "collection" of child Forms vs. a single, known reference are two
very different things - not "duplication".
<snip>
Did I imply that the OP shouldn't?
Yes.
That's 100% your interpretation because that was not my intention at all.
And I don't think your code is simpler at all, BTW. I've glanced at it
twice and I have no idea what it's doing - I'm just assuming that it
works :)
It is one-off code that can be placed in 1 place in the app. It is more
complex than yours but once it's done it doesn't need to be duplicated in
potentially hundreds of locations. If you're really concerned about the
complexity of mine, the number of lines could easily be reduced.
I was never really concerned at all with your code or its level of
complexity. I've always felt that the OP should choose the best solution,
which may very well have been yours.
But assuming hundreds of modal Forms isn't very realistic. The OP never
said how many modals there are. And since your assuming things, how about
if each of the modals all derive from a common ancestor? In that case my
solution would work quite nicely and probably would be more appropriate than
yours.
And I still don't think either of our solutions even deserve all this
attention :)
Marc was completely off (no offense Marc :), and I don't see how our
solutions are even close.
Yours closes each form in many locations, mine does the same thing from
one location. Yours uses a member variable where mine uses the owner
property.
They're completely different :)
My solution is based on the fact that a modal dialog will "buffer" the
FormClosed event until all other owned modals are closed first - that's
how modal Forms behave. So, my code closes the one and only known child
modal (via a field reference) when the Owner itself is being closed, and
the FormClosed events for each modal are raised in a chain-reaction from
top-most to first. It's quite simple, really.
I know how yours works, I used it to write a more generic solution. :-)
The revised code in your adjacent post is much clearer. I'm not sure how my
solution helped you to write it, but if it works - great :)
--
Dave Sexton
.
- Follow-Ups:
- Re: Closing down a hierarchy of modal windows nicely
- From: Michael C
- Re: Closing down a hierarchy of modal windows nicely
- References:
- Closing down a hierarchy of modal windows nicely
- From: Chukkalove
- Re: Closing down a hierarchy of modal windows nicely
- From: Dave Sexton
- Re: Closing down a hierarchy of modal windows nicely
- From: Marc Vangrieken
- Re: Closing down a hierarchy of modal windows nicely
- From: Dave Sexton
- Re: Closing down a hierarchy of modal windows nicely
- From: Michael C
- Re: Closing down a hierarchy of modal windows nicely
- From: Dave Sexton
- Re: Closing down a hierarchy of modal windows nicely
- From: Michael C
- Re: Closing down a hierarchy of modal windows nicely
- From: Dave Sexton
- Re: Closing down a hierarchy of modal windows nicely
- From: Michael C
- Re: Closing down a hierarchy of modal windows nicely
- From: Dave Sexton
- Re: Closing down a hierarchy of modal windows nicely
- From: Michael C
- Closing down a hierarchy of modal windows nicely
- Prev by Date: Re: User control constructor called twice
- Next by Date: Re: Thread ending
- Previous by thread: Re: Closing down a hierarchy of modal windows nicely
- Next by thread: Re: Closing down a hierarchy of modal windows nicely
- Index(es):
Relevant Pages
|