Re: Window closed event?
- From: "TaylorMichaelL" <TaylorMichaelL@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 19 Sep 2005 04:21:04 -0700
I would recommend that you create an interface that you require all user
controls to implement. You can then add a method to notify the user control
that it is closing. The UC should then clean up its own resources. Within
the tree control you can also raise an event notifying outside listeners that
the view is changing. Finally you should consider simply hiding the UC when
it switches away instead of closing it. Some views may be very costly to
create and therefore you could leave it up to the view itself to decide
whether it should close or simply hide itself. It depends on how often the
view is likely to change (for example in Explorer the file view is normally
the only view seen so unloading and reloading it each time the user changes
their selection is overkill).
As a side note since you only have a single view on the right side you can
simply hide the view when the user selects another node. In the
OnVisibleChanged event of your UC you could then do your cleanup (or at least
toggle it on or off). This might not work well if your app minimizes but
trial and error would reveal the issues.
Michael Taylor - 9/19/05
"Paul" wrote:
> Herfried K. Wagner [MVP] wrote:
> > "Paul" <---@xxxxxxx> schrieb:
> >
> >> In a windows forms app how do you know a window is closing? There
> >> seems to be no event for this.
> >>
> >> I have timer object that appears to be firing after the window is
> >> closed (maybe) and I want to shut down and dispose the timer when the
> >> window closes.
> >
> >
> > Check out the form's 'Closing' and 'Closed' events. In .NET 2.0 forms
> > provide 'FormClosing' and 'FormClosed' events. Take a look at the
> > form's overridden 'Dispose' method too. You can add code for disposing
> > objects there.
> >
>
> I should have explained my design. c# windows forms app. Tree view on
> the left, vertical splitter, and view pane on the right (explorer
> interface style). The "views" are UserControl class. When I switch views
> using the tree control, I'd like to know when my views close.
>
> Should I instead try to use the Form class for my views instead of
> UserControl? The app has been working perfectly and the timer might not
> be a problem. I'm still sort of surprised there is no generic way to
> detect precisely when a window is closed or destroyed.
>
>
.
- References:
- Re: Window closed event?
- From: Herfried K. Wagner [MVP]
- Re: Window closed event?
- Prev by Date: RE: Combo refresh/binding problem
- Next by Date: Re: Loading (Running) EXE into GAC
- Previous by thread: Re: Window closed event?
- Next by thread: FindDialog for RichTextBox problem
- Index(es):
Relevant Pages
|
Loading