Form lifecycle question....

  • Thread starter Thread starter craig
  • Start date Start date
C

craig

Assume that you have two forms, Form A and Form B.

Code in Form A instantiates and maintains a reference to Form B. Form B
contains an event handler for one of the buttons on Form A. This event
handler is "wired up" when form B is instantiated, in the Form_Load event.

When code in Form A eventually releases its reference to Form B, form B
needs to remove its event handler from Form A. What would be the best way
to make this happen? I could do this by making Form A call a public method
on Form B that releases the event handler. But is there a more automatic
way of making this happen?

Thanks!
 
You should stick your code to free up resources in the dispose method for
the forms and then just call the Dispose method of Form B from Form A.

Take care,
Ben S. Stahlhood II
 

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

Back
Top