Re: Closing down a hierarchy of modal windows nicely

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: Closing down a hierarchy of modal windows nicely
    ... You are storing a reference to an owner form.The Form class has an Owner property. ... When the Form is a child to another ... FormClosed event until all other owned modals are closed first - that's how ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Closing down a hierarchy of modal windows nicely
    ... You are storing a reference to an owner form. ... When the Form is a child to another ... FormClosed event until all other owned modals are closed first - that's how ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Replacing key values with their referenced data records
    ... parent tables and child tables and then use the DataColumn.Expression ... you must include the reference ... Additionally, once I can get it to display properly, I need ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • RE: Display mutliple 1-1 tables in DataGrid?
    ... A column in a child table may be referenced in an expression by prepending ... column named Price in the child table. ... example, if a table has two child tables named Customers and Orders, and the ... the reference would be: ...
    (microsoft.public.dotnet.framework.adonet)
  • Re[2]: [PHP] OO parent/child relationship
    ... GS> I plan on converting a file of user management functions to a class. ... GS> If I do, then that new class, is going to need a reference to the DB object. ... The parent class capable of talking to the child classes. ...
    (php.general)