tags:

views:

102

answers:

2

Hi,

If I have a close button on a form, and I want them to be able to click it but affectively act as a 'Hide' button, how can this be easily done? Is there no way to abort the FormClosing event from executing fully?

Cheers

A: 

It should be pretty straight forward...

To cancel the closure of a form, set the Cancel property of the FormClosingEventArgs passed to your event handler to true.

Concerning part two of the question with hiding the window...hide to taskbar or hide to notification area?

cyberzed
+4  A: 

You could just capture the Form_Closing event and stop the default action, then instead of closing the form just Hide it:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    e.Cancel = true;
    this.Hide();
}
GenericTypeTea