Revuen Ben Dror
Revuen Ben Dror

Reputation: 237

How can i create/add an event of contextMenuStrip1 that is connected with notifyIcon?

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

Answers (1)

Idle_Mind
Idle_Mind

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:

Double Click to get default handler

Upvotes: 1

Related Questions