Re: Window closed event?



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.
>
>
.



Relevant Pages

  • Re: SendKeys Method when Computer is Locked
    ... "handle" of the child window you are interested in. ... unless the control has focus, ... app to respond. ... Personally I prefer the system api approach. ...
    (microsoft.public.scripting.wsh)
  • Re: Automated GUI testing
    ... Having this ideas in mind you can succeed if you control the program ... naming can make your job of locating the proper window and control ... >1) Window Definitions Scripts ... This definition must be 'tied' to the actual app windows, ...
    (microsoft.public.vc.mfc)
  • Re: MORE Lyle Blake Info......
    ... >control with a static window beside it to show the percentage. ... The lightweight controls will be part of the DLL ... unloaded - the DLL might be unloaded without the App terminating ...
    (comp.lang.pascal.delphi.misc)
  • Re: Window Refresh in OnPaint()
    ... even i guess the problem is different while creation of the control ... starts and the dialog window is newly created, i see the control is not ... pointed out in some other replies, dont call base class's OnPaint. ... Does it work after the app start (ie when you resize etc or move the ...
    (microsoft.public.vc.mfc)
  • Re: Entwicklung von Unix-Anwendung mit C++ (m/w)/ NRW : Ref.-Nr.: 37302/1
    ... I am responsible for design and implementation of the persistent data server working with mySQL. ... Developed within very short time the product was successfully installed ... Reengineering and implementing a display tool for Experimental Physics Industrial Control System ... Developed an operator interface under X Window for High Energy Physics Accelerator Control System. ...
    (de.markt.arbeit.d)

Loading