OnClosing event doesn't close form

  • Thread starter Thread starter C# Dev
  • Start date Start date
C

C# Dev

Hi Group,

I raise OnClosing event in a handler of a menu item. It invokes the
OnClosing registered delegate but it doesnot close the form.
But if i click on the close icon [X] of the form it invokes the OnClosing
registered delegate and then closes the form. Can anyone
help why same event handler (OnClosing) have different behaviour when
invoked from code or clicked on from close button [X].
// Following is the menu event handler raising OnClosing event.

private void miExit_Click(object sender, System.EventArgs e)

{base.OnClosing(new CancelEventArgs(false)); }



Thanks.
 
You should call the form's Close method. It will setup the necessary
messages for the window to shut down and then call the OnClosing event.
OnClosing is called by the framework as the form is closing from the X
button or some other programmatic method.
 
Almost!
let's see....
You should call the form's Close method. It will setup the necessary right!

messages for the window to shut down and then call the OnClosing event.
OnClosing is called by the framework as the form is closing from the X
wrong! no need to call OnClosing again!, it's already done by the call to
close
 
Back
Top