TTrayIcon (Delphi)
Description
This example uses a tray icon and an application events component on a form. When the application runs, it loads the tray icon, the icons displayed when it is animated, and it also sets up a hint balloon. When you minimize the window, the form is hidden, a hint balloon shows up, and the tray icon is displayed and animated. Double-clicking the system tray icon restores the window.
Code
procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
{ Hide the window and set its state variable to wsMinimized. }
Hide();
WindowState := wsMinimized;
{ Show the animated tray icon and also a hint balloon. }
TrayIcon1.Visible := True;
TrayIcon1.Animate := True;
TrayIcon1.ShowBalloonHint;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
MyIcon : TIcon;
begin
{ Load the tray icons. }
TrayIcon1.Icons := TImageList.Create(Self);
MyIcon := TIcon.Create;
MyIcon.LoadFromFile('icons/earth1.ico');
TrayIcon1.Icon.Assign(MyIcon);
TrayIcon1.Icons.AddIcon(MyIcon);
MyIcon.LoadFromFile('icons/earth2.ico');
TrayIcon1.Icons.AddIcon(MyIcon);
MyIcon.LoadFromFile('icons/earth3.ico');
TrayIcon1.Icons.AddIcon(MyIcon);
MyIcon.LoadFromFile('icons/earth4.ico');
TrayIcon1.Icons.AddIcon(MyIcon);
{ Set up a hint message and the animation interval. }
TrayIcon1.Hint := 'Hello World!';
TrayIcon1.AnimateInterval := 200;
{ Set up a hint balloon. }
TrayIcon1.BalloonTitle := 'Restoring the window.';
TrayIcon1.BalloonHint :=
'Double click the system tray icon to restore the window.';
TrayIcon1.BalloonFlags := bfInfo;
end;
procedure TForm1.TrayIcon1DblClick(Sender: TObject);
begin
{ Hide the tray icon and show the window,
setting its state property to wsNormal. }
TrayIcon1.Visible := False;
Show();
WindowState := wsNormal;
Application.BringToFront();
end;
Uses
- Vcl.ExtCtrls.TTrayIcon ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.Icon ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.Visible ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.Hint ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.BalloonFlags ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.BalloonHint ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.BalloonTitle ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.Animate ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.AnimateInterval ( fr | de | ja )
- Vcl.ExtCtrls.TCustomTrayIcon.Icons ( fr | de | ja )