/// <include file='doc\Form.uex' path='docs/doc[@for="Form.Close"]/*' />
/// <devdoc>
/// <para>Closes the form.</para>
/// </devdoc>
public void Close() {
if (GetState(STATE_CREATINGHANDLE))
throw new InvalidOperationException(SR.GetString(SR.ClosingWhileCreatingHandle, "Close"));
if (IsHandleCreated) {
closeReason = CloseReason.UserClosing;
SendMessage(NativeMethods.WM_CLOSE, 0, 0);
}
else{
// MSDN: When a form is closed, all resources created within the object are closed and the form is disposed.
// For MDI child: MdiChildren collection gets updated (VSWhidbey# 368642 & 93550)
Dispose();
}
}