System Tray Icon for .NET Core Console App

Notification icon or tray icon is supported for .NET Core 3.0 onwards only. Install .NET Core 3.0 Preview from https://dotnet.microsoft.com/download/dotnet-core/3.0 to add the tray icon for a console or windows application.

Once installed, create a new console application using .NET Core in Visual Studio

Add references to System.Windows.Forms and System.Drawing.Common from .NET Core 3.0 library, which will be located at C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\3.0.0-preview3-27504-2.

Also, add your tray icon. Here, I have used the cat.ico for the tray icon.

In your program, use the NotifyIcon from System.Windows.Forms namespace to create a tray icon and add the notification message to it.

Sample code:

Console.WriteLine(“Hello Kitten!”);
NotifyIcon icon = new NotifyIcon();
icon.Icon = new System.Drawing.Icon(“./cat.ico”);
icon.Visible = true;
icon.BalloonTipText = “Hello from My Kitten”;
icon.BalloonTipTitle = “Cat Talk”;
icon.BalloonTipIcon = ToolTipIcon.Info;
icon.ShowBalloonTip(2000);
Console.Read();

Ensure that the cat.ico will be copied to your output directory

Run the application and observe the tray icon and notification appearing near the task bar.

 

About ambilykk

I am a Technology Evangelist on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Azure and Visual Studio. Technology adoption and learning is my key strength and technology sharing is my passion.
This entry was posted in .NET Core and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s