none
Any Difference between Form.Close and Form.Dispose?

    General discussion

  • Can anybody tell me is there any difference between Form.Close and Form.Dispose? I know inside Form.Close, Form.Dispose will be called. Any extra things processed inside Form.Close not in Form.Dispose?
    Thursday, September 04, 2003 9:47 PM

All replies

  • Form.Close() sends the proper windows messages to shut down the win32 window. During that process, if the form was not shown modally, Dispose is called on the form. Disposing the form frees up the unmanaged resources that the form is holding onto.  

    If you do a form1.Show() or Application.Run(new Form1()), Dispose will be called when Close() is called.

    However, if you do form1.ShowDialog() to show the form modally, the form will not be disposed, and you'll need to call form1.Dispose() yourself.  I believe this is the only time you should worry about disposing the form yourself.

    Hope this helps -
    Jessica
    Saturday, September 06, 2003 2:25 AM
  • Thank you very much, Jessica.
    Saturday, September 06, 2003 9:34 AM
  • What do you mean by proper windows messages? Can you please tell some examples..

     

     

    Thanks,

    Chris

    Thursday, December 15, 2011 5:02 AM