Reputation: 237
I added a notifyIcon to my designer in Form1 . Then i hid it :
private void Form1_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide();
}
Then added in the designer contextMenuStrip . In the notifyIcon in the property ContextMenuStrip i selected the contextMenuStrip1 .
Then in the contextMenuStrip in the items edit menu i added a new item called it for the test : Close Application .
Now when i'm running my application and resize down hid the Form i see the icon in the tray icons right click on it i see the menu : Close Application
Now the problem is where/how do i create an event for the Close Application so one single click on it with the mouse left button will do something ? (Close the application)
Upvotes: 0
Views: 343
Reputation: 39122
Double click the "Close Application" menu item to get a stub handler inserted for you. Now just add in the Close() method for the Form:
private void closeApplicationToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
EDIT: Here's a picture just to make it clearer:
Upvotes: 1