Lazarus

Programming => Widgetset => Other => Topic started by: benohb on February 02, 2019, 03:43:17 am

Title: TfpgSystemTrayIcon in Fpgui
Post by: benohb on February 02, 2019, 03:43:17 am
Google does not help much
How use TfpgSystemTrayIcon in Fpgui
Any examples? I use Linux   %)
Title: Re: TfpgSystemTrayIcon in Fpgui
Post by: Graeme on May 10, 2019, 05:13:17 pm
Sorry for the late reply. I've already added an example to the documentation, but the current online docs is equivalent to the "master" branch (last stable released branch), and not the more up-to-date "maint" or "develop" branches.

Anyway, add the following code to your main form's AfterCreate() method.

Code: Pascal  [Select][+][-]
  1.   pmTray := TfpgPopupMenu.Create(self);
  2.   with pmTray do
  3.   begin
  4.     Name := 'pmTray';
  5.     SetPosition(256, 128, 120, 20);
  6.     AddMenuItem('Start Timer...', '', nil);
  7.     AddMenuItem('Stop Timer...', '', nil);
  8.     AddMenuItem('-', '', nil);
  9.     AddMenuItem('Show Form', '', @miShowFormClicked);
  10.     AddMenuItem('-', '', nil);
  11.     AddMenuItem('Quit', '', @miFileQuitClicked);
  12.   end;
  13.  
  14.   TrayIcon := TfpgSystemTrayIcon.Create(self);
  15.   with TrayIcon do
  16.   begin
  17.     Name := 'TrayIcon';
  18.     SetPosition(256, 240, 20, 20);
  19.     PopupMenu := pmTray;
  20.     ImageName := 'stdimg.folderhome';
  21.   end;
  22.  

You define a popup menu, which in turn you will assign to the PopupMenu property of the systemtray component. There are a couple of properties you can adjust to configure the systemtray appearance.

TinyPortal © 2005-2018