When we want to show the icon of our application in System tray then we use notify Icon control from toolbar in our application.
After adding notify Icon to our form we have to write code.
private void frmRecord_Resize(object sender, EventArgs e)
{
//if form is minimized then it will not be displayed in taskbar.
if (FormWindowState.Minimized== this.WindowState)
Hide();
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
//this will maximize the application minimized to System tray.
Show();
WindowState = FormWindowState.Normal;
}
We can also create a context menu of the notify icon. To create the menu we have to add
ContextMenuStrip control from toolbar.
We can add the menu element by selecting ContextMenuStrip. Here I’ve added two options on the menu. To link the menu to notify icon we have to set contextMenuStrip property of notifying icon to added contextMenuStrip.
Code for contextmenustrip options.
private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
Screen Shot
Anonymous User
13-Mar-2019Thank You for the guidance.
Sushant Mishra
11-Jul-2017Keep sharing these types of articles.