Cannot able to close Form?

It is a fascinating bug that forces a Windows Form to go into a condition where it cannot be closed. Are you using the initial version of the .NET framework with SP1 installed?
Want to check this?

  • Build a new form, F1.
  • Set a user control U1 on top of it.
  • Locate one more user control, U2, onto the control U1.
  • To end with, put a button onto U2.
  • Write down an event handle for the button click that causes the user control U2 to be detached from its parent, U1.
  • Run the application.
  • Click on the button.
  • You should wind up with a form.
  • Now make an attempt to close the form by clicking on the close button.
  • It does not work. Am I right?
    Reason:
    The form is saying NO to close because its Close method is trying to authenticate the control first. The validation should fail because its unvalidatedControl private member still points to the button which has been detached from the hierarchy.

    How to overcome:
    After get rid of the user control U2, call a.OnControlRemoved (c) that clear the unvalidatedControl variable.

No comments yet.

Leave a comment

Request a Free SEO Quote