Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding the 'X' button on a form

Status
Not open for further replies.

rsfoley

Programmer
Apr 16, 2002
56
0
0
US

I have been trying to figure out, and search for how you can override the normal closing operation of a Form when a user hits the 'X' button, so that it just HIDES the form instead.

The closest I found in a forum someplace was they said to override OnClosing if you want to change how to handle the 'X' button default operations.

Like so:

protected override void OnClosing(CancelEventArgs e)
{
this.Hide();
}

However this does not work. The form is still disposed of, and when I try to show the form again I get an exception say just that.

Does anyone know how to do this, or can point me to an article or forum message someplace that explains this?

Thanks in advance...

Rodney
 
I'd like to know about this myself. Let me know what you find out. Thanks
 
Well I found the answer... I was on the right track, I just needed to add the following line to the method override:

e.Cancel;

This cancels the event from proceeding, and lets you do what you want.

So there you go...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top