When I press the button (X), I don't want it to exit the application. but I want it to close the form and hide it from the task bar. At the end I will exit it from the icon I made.
My program will look like wamp or xamp. I will run or exit from the icon.
Any help or idea please! Thanks !
Jihen AremPosted Apr 22, 2014, 12:13 PM
VulpesPosted Apr 21, 2014, 6:13 PM
Subject to that, you should be able to do what you want by handling the form's FormClosing event:
private bool firstClosing = true;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (firstClosing && e.CloseReason == CloseReason.UserClosing)
{
this.ShowInTaskbar = false;
this.Visible = false;
e.Cancel = true;
firstClosing = false;
}
}
The bool field, firstClosing, is used to ensure you'll be able to close the application later using the icon. The second time you close it, the code which stops the application from closing will be by-passed.