MDI app & events

G

Guest

I'm currently creating an mdi application and trying to use events between
various forms within the app for communication.

I have the events working without any problem when all the forms are open
but my problem comes when a form that has subscribed to an event is closed
and the event handler is not removed.

I think I've caused myself problems with the way that I open one form from
another,
to make things easier the code below is in the Display form (showing
summary info) and it is opening a add form:

try
{
this.Cursor = Cursors.WaitCursor;
AddOrder add = new AddOrder();
add.OrderAdded += new
AddOrder.OrderAddedEventHandler(this.OrderAdded);
add.MdiParent = this.MdiParent;
add.Show();
}
catch (Exception)
{

throw;
}
finally
{
this.Cursor = Cursors.Arrow;
}

Since I don't keep a reference to the AddOrder form that I added the handler
too when I close the Display form that originally created the AddOrder form
I am unable to remove the handler and an error is occuring when I raise an
event in the AddOrder form.

Any ideas of a good way to deal with removal of event handlers in this
situation or not raising the event?
 
N

Nathan

I found a solution in that in my form I kept an ArrayList of forms that
I had opened and if I closed I looped through the ArrayList and ensured
I removed all of the event handlers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top