Search code examples
c#system-traynotifyiconminimized

Minimize to system tray


i was following the instruction on page

but then, there's no icon attached for the application, so after the form is hidden, i cannot reshow the form, since there's no icon on the system tray,

how do i resolve this ?

here is my code

 private void Form1_Resize(object sender, EventArgs e)
    {
        if (FormWindowState.Minimized == this.WindowState)
        {
            notifyIcon1.Visible = true;
            cmd.cetakSukses(ident.judul_App + " Diperkecil ke dalam System Tray");
            notifyIcon1.BalloonTipText = ident.judul_App + " Diperkecil ke dalam System Tray";
            notifyIcon1.BalloonTipTitle = ident.judul_App;
            notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
            notifyIcon1.ShowBalloonTip(500);                
            this.Hide();
        }
        else
        {                

        }
    }

update :

i have attached the icon, and the icon still not showing on the system tray

enter image description here

and i figured how to make the form showing, i need to add the following code to notifyicon

 private void notifyIcon1_DoubleClick(object sender, EventArgs e)
    {
        this.Show();
    }

Solution

  • You can set the notify icon at design using the Properties sheet:

    Notify Icon Properties

    Or you can add/change the icon property at runtime using the following code:

    notifyIcon1.Icon = new Icon("appicon.ico");