Delphi XE Change System Tray Icon with TTrayIcon (No Blurry)

Posted on August 27, 2020 at 3:19 pm

You can change system tray icon by using TTrayIcon and TImageList:

procedure TForm1.Button4Click(Sender: TObject);
begin
  TrayIcon1.IconIndex := 0;
end;
 
procedure TForm1.Button5Click(Sender: TObject);
begin
  TrayIcon1.IconIndex := 1;
end;

However this seems to add a blurry effect on the icon (not good).

To avoid this issue, just use this method:

procedure TForm1.Button4Click(Sender: TObject);
begin
  TrayIcon1.Visible := False;
  TrayIcon1.Icon.LoadFromFile('icons\yellow.ico');
  TrayIcon1.Visible := True;
end;
 
procedure TForm1.Button5Click(Sender: TObject);
begin
  TrayIcon1.Visible := False;
  TrayIcon1.Icon.LoadFromFile('icons\red.ico');
  TrayIcon1.Visible := True;
end;

This way the icon looks mostly pixel-perfect in the system tray.

Tested also on Windows 7 and Windows 10.

If you want to load the icon from the ICONS resource:

procedure TForm1.Button4Click(Sender: TObject);
begin
  TrayIcon1.Visible := False;
  TrayIcon1.Icon.LoadFromResourceName(hInstance, 'ICON1');
  TrayIcon1.Visible := True;
end;

Receive updates via email

Other Posts

Updated Posts