This is a migrated thread and some comments may be shown as answers.

Unsubscribing to static events on forms where DocumentWindowis parent

2 Answers 40 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 07 Dec 2012, 10:56 AM
I have a few global static events that some of my forms subscribe to.  The subscription happens in the Form.Load event of each form.  Those forms are added to a DocumentWindow then to the DockManager.  The subscription is great, everybody's listening fine.  Now when I close a DocumentWindow, the forms OnClosing events doesn't happen thus not unsubscribing to the static event I had wired.  So now when another form (document window) fires the static event I get an exception from the closed form where the static handler is trying to work but the form doesn't exists anymore.

Any ideas on how to unsubscribe to static events on forms that are children to DocumentWindows once closed?

Thanks,
Byrd

2 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 07 Dec 2012, 04:33 PM
Figured out a hack.  I simply created an Interface called IStaticEventHandler and added just one method called UnsubscribeFromEvents().  The form added to the DockWindow implements this.

Now, OnDockWindowClosing test to see if Controls[0] (the form is the only control added) of the DockWindow is of type IStaticEventHandler.  If it is set a local variable to Controls[0] as an IStaticEventHandler type then called the UnsubscribeFromEvents() method.

That worked!!
0
Julian Benkov
Telerik team
answered on 12 Dec 2012, 01:05 PM
Hi Brian,

I am glad to hear that you found a way to achieve the desired requirement.

If you have additional questions regarding your scenario, please open a new support ticket and send me a sample project which demonstrates it. This will allow me to assist you adequately.

Greetings,
Julian Benkov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
Dock
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or