Override Form Close Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone tell me how to override the X button on the form.
I cant find it in the overrides drop down.

When the X is clicked it destroys the instance of the form. I want to
stop this from happening

Cheers
 
Add an event handler to the Closing event. To prevent the Form from closing
set the set the Cancel property of the CancelEventArgs to true. Something
like below:

private void MainForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{

if(!allowed)

e.Cancel = true;

}
 
when the button X is pressed, the form isn't closed. the form is
minimized. if the button ok is displayed and pressed then the form is
closed

take look at http://samples.gotdotnet.com/quickstart/compactframework/
in the Pocket PC Form Styles.

anyway in your case, since the form isn't closing you can't handle it
with the closing event. Handle the Deactivate event instead
 
Hi Strider,

FYI Niam is talking about the Pocket PC platform on which the X behaves as
he describes.

Cheers
 
Hi,

On Windows CE .NET, the form should fire Closing event before closing and
Closed event when the Form is closed.

However, if you call Application.Exit, these two event will NOT be
triggerred. If you have to execute the code inside these event handlers you
should call Form.Close for each open form before calling Application.Exit.

Thanks

Ercan Turkarslan
Microsoft Mobile Devices Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top