Tim Huffam

Dotting the I and crossing the T of I.T.

  Home  |   Contact  |   Syndication    |   Login
  115 Posts | 0 Stories | 623 Comments | 677 Trackbacks

News

Archives

Post Categories

Interesting Blogs/Links

Doing some winforms dev for a change - and had a need to hide a form, instead of closing it, when the user clicked the standard windows close form button (little cross [x] icon on the top right corner of the form).

The solution is to create a handler for the FormClosing event of the form, then force the form to be hidden, then, the important part, cancel the close event...

Eg:

// Use this event handler for the FormClosing event.

private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
{
  this.Hide();
  e.Cancel = true; // this cancels the close event.
}

Tim

posted on Thursday, September 13, 2007 4:37 AM

Feedback

# re: How to hide a form instead of closing it - with C# .Net 11/17/2007 9:07 AM Niklas
Love you! thanks, belive it or not but this was hard to find some info on.

# re: How to hide a form instead of closing it - with C# .Net 12/24/2007 12:04 PM Rita
lets say that i wan to close the sesion, it wouldn't let me , how can avoid that ??

# re: How to hide a form instead of closing it - with C# .Net 2/28/2008 3:57 AM fahem
hiding form using c#.net

# re: How to hide a form instead of closing it - with C# .Net 4/3/2008 10:57 PM Jibran
this is not allow windows to shutdown or restart if application is running.

# re: How to hide a form instead of closing it - with C# .Net 6/27/2008 12:06 PM Avi
Thanks!

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 7 and 8 and type the answer here: