Thursday, January 10, 2019

Adding system tray to a project c# and a console application


Need to add to references

System.Windows
System.Windows.Forms
System.Drawing

so that the Icon reference will work



            NotifyIcon tray = new NotifyIcon();
            tray.Visible = true;

            tray.Icon =
                new System.Drawing.Icon(System.Environment.GetFolderPath
                (System.Environment.SpecialFolder.Personal)
                + @"\Icon.ico");

            tray.Text = "Ice Essentials";

An Icon.ico file must exist as this example uses that method to get the "ico"-ized bitmap file for use.

If one were using windows with forms, other than a console window project to start with, the ico object could be taken from objects created for forms.  But this allows the system tray object to be created w/o that on a console type exe in c#

No comments:

Post a Comment