0

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();
    }
Community
  • 1
  • 1
Cignitor
  • 891
  • 3
  • 16
  • 36
  • @MarioStoilov i mean an icon in the system tray, so when we double click the icon on the system tray, it will make the form shown – Cignitor Apr 23 '14 at 13:31
  • I meant did you try to just attach an icon. It is logical that if you have no icon set, there would be nothing to show in the tray. – Mario Stoilov Apr 23 '14 at 13:35
  • @Cignitor you have add the icon for the Form. You need to add the icon to the NotifyIcon control. See my answer below. – Black Frog Apr 23 '14 at 13:42
  • System Tray? What's that? Do you mean the Notification Area? Please don't do this, you're abusing the purpose for the Notification Area. Please don't clutter that area, it's for notifying the user about things that need action. Use the taskbar when you want to minimise the application (it's what users expect). – Skizz Apr 23 '14 at 13:44

3 Answers3

1

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");
Black Frog
  • 11,595
  • 1
  • 35
  • 66
  • oh yes, i have followed your instruction, the icon was there, on my system tray, but then, there's no way to show the form, i have double-clicked the icon, the form is not showing. – Cignitor Apr 23 '14 at 13:44
  • You need to add code to the [NotifyIcon.DoubleClick](http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.doubleclick.aspx) Event to change the visibility of the form. – Black Frog Apr 23 '14 at 13:48
0

You need to give you application an icon either by using visual studio or programatically.

You can do it in VS by going to the project properties and selecting the application tab

Or you can set it at runtime if you have icon files attached to your project already.

private NotifyIcon appIcon = new NotifyIcon();

appIcon.Icon = new System.Drawing.Icon("myApp.ico");
haxtbh
  • 3,467
  • 1
  • 21
  • 22
0

This is how i implemented through code behind for a WPF app.

    System.Windows.Forms.NotifyIcon m_NotifyIcon;

    public StartWindow()
    {
        InitializeComponent();

        m_NotifyIcon = new System.Windows.Forms.NotifyIcon();
        m_NotifyIcon.Icon = new System.Drawing.Icon(IconPath);
        m_NotifyIcon.Visible = true;
        m_NotifyIcon.BalloonTipTitle = "Tip here";
        m_NotifyIcon.Text = "Text here";

        m_NotifyIcon.DoubleClick += delegate(object sender, EventArgs args)
        {
            this.Show();
            this.WindowState = WindowState.Normal;
        };
    }

    protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
    {
        try
        {
            if (m_NotifyIcon != null)
                m_NotifyIcon.Dispose();
        }
        catch { }

        base.OnClosing(e);
    }

    protected override void OnStateChanged(EventArgs e)
    {
        if (WindowState == WindowState.Minimized)
            this.Hide();

        base.OnStateChanged(e);
    }