本文整理自网络,侵删。
procedure TForm1.Button4Click(Sender: TObject);
begin
TrayIcon1.IconIndex := 0;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
TrayIcon1.IconIndex := 1;
end;
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;
这样,图标在系统任务栏中看起来大部分都是像素完美的。
在Windows 7和Windows 10上也进行了测试。
如果要从ICONS资源中加载图标:
procedure TForm1.Button4Click(Sender: TObject);
begin
TrayIcon1.Visible := False;
TrayIcon1.Icon.LoadFromResourceName(hInstance, 'ICON1');
TrayIcon1.Visible := True;
end;
相关阅读 >>
Delphi 判断指定字符串是否开头 startstext用法
Delphi中combobox.items.indexof用法
更多相关阅读请进入《Delphi》频道 >>