0

I have PPP Dialer program in C#. After successfull connection, it minimize to system tray with icon.

How can I dynamically change notifyicon image in Tray according to the connection state?

Example:

If connection is idle: ICON-IMAGE-1 If connection is Connected: ICON-IMAGE-2 If connection is Disconnected: ICON-IMAGE-3

I have the triggers on events, just wanted to know how to change try icon according to the event.

Syed Jahanzaib
  • 333
  • 6
  • 18

1 Answers1

2

You can use NotifyIcon

private NotifyIcon _nIcon;

I do it like this. I first initialize the notification in the app constructor.

System.IO.Stream iconStream = System.Windows.Application.GetResourceStream( new Uri( "pack://application:,,,/;component/Resources/offline.ico" )).Stream;
_nIcon = new NotifyIcon();
_nIcon.Icon = new System.Drawing.Icon(iconStream); 

and then when your connection changes:

System.IO.Stream iconStream = System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/;component/Resources/online.ico")).Stream;
_nIcon.Icon = new System.Drawing.Icon(iconStream);

Hope this helps.

  • 1
    thank you for your time and reply. I finally made it by adding the icons/images in the project resources, then called it using `notifyIcon1.Icon = Resource1.icon_online;` & `notifyIcon1.Icon = Resource1.icon_offline;` in ras connection watcher. :) – Syed Jahanzaib Mar 24 '17 at 06:00