How to Minimize Application to Tray

Sharing is Caring

I’m not sure how many times I have been someone ask for help on the MSDN forums, email me, or come over and ask me in the case of coworkers. The steps to have an application minimized to tray are very simple.

      Create .NET Windows Application.
      Create .NET application.
      Add Tray Notifcation Icon to Windows form.
      Create Icon (using .NET, or other software). The icon should be 16×16
      Using either code or the visual editor you need to add the icon.
      As you may have noticed there’s no minimize event on the form. We need to use the form’s Resize Event and make sure that we check to see if the WindowState is Minimized. If the WindowState is minimized we need to make our form invisible and make the tray icon visible.
      Depending on your application, and how you have designed things you should use either the click or doubleclick events on the notifyicon to set the visibility of the form again and hide the trayicon again.


//No Minimize Event, so we need to use Resize event & check WindowState
private void frmMain_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = false;
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(50);
}
}

//Make form visible and notify icon invisible.
private void notifyIcon1_Click(object sender, EventArgs e)
{
this.Visible = true;
notifyIcon1.Visible = false;
}

Author: Brian Cline

Brian is a programmer living in Niagara Falls with ten years of development experience. He is passionate about automation, business process re-engineering, and gamification. For the last six years or so, he has been working with Salesforce and JavaScript.

Related Posts

Sharing is Caring

Comments are closed.