User Tools

Site Tools


k19:k19.2:start

19.2 TrayIcon - TrayIcons

The gb.gui.trayicon component allows you to display a tray icon in the taskbar. The following system tray protocols are supported:

  • The old X11 Free Desktop System Tray specification,
  • the KDE DBus system tray protocol and
  • The Unity DBus system tray protocol.

The DBus system protocol should be standard, but unfortunately KDE and Ubuntu implementations are not compatible with each other! The component therefore examines at runtime which type of system tray is available on the system. The appropriate protocol is then selected automatically. The component gb.dbus is only loaded if the DBus protocol is also used.

While the TrayIcon class implements a tray icon, the TrayIcons class provides a virtual collection of all TrayIcon objects managed by an application.

19.2.1 Class TrayIcon

The class TrayIcon has these properties:

19.2.1.1.1 Properties

PropertyData typeDescription
IconPictureReturns the icon or sets the icon for the tray icon.
PicturePictureA synonym for the icon property.
PopupMenuStringThe name of the menu is set or returned when a user clicks on the tray icon.
TagVariantReturns the value of the Tag property or sets the value of this property. This property is intended for the programmer and is never used by the component. tag can have any value of type Variant.
ToolTipStringReturns the text of the tool tip or sets the text of the tool tip displayed for the tray icon.
TextStringA synonym for the tooltip property.
VisibleBooleanSpecifies whether the tray icon is visible or sets True to indicate that the tray icon is visible.

Table 19.2.1.1.1.1: Properties of the TrayIcon class

19.2.1.2.2 Properties

The class TrayIcon has only three methods:

MethodDescription
Delete ()Deletes a TrayIcon object.
Hide()Hide the tray icon from the system tray.
Show ()Displays the tray icon in the system tray.

Table 19.2.1.2.1: Methods of the class TrayIcon

Note:
If you want to close the window of an application that uses a TrayIcon object, you must first use the TrayIcon.Hide () method!

19.2.1.3 Events

Only three events are triggered by the class TrayIcon:

  • _Click,
  • _MiddleClick and
  • _Scroll (Delta As Float, Orientation As Integer)
EventDescription
ClickThis event is triggered when the user clicks on the tray icon with the left mouse button.
MiddleClickThis event is triggered when the user clicks on the tray icon with the middle mouse button.
Scroll (Delta As Float, Orientation As Integer)This event is triggered when the user scrolls with the mouse over the tray icon.

Table 19.2.1.3.1: Events of the TrayIcon class

Notes on the Scroll (…) event

  • Delta is the delta value of the scrolling event. A positive value for Delta indicates that the wheel has been turned forward by the user. A negative value indicates that the wheel has been turned back to the user.
  • Orientation is the orientation of the scrolling event. Orientation can be one of the following constants: TrayIcon, Horizontal (0) and TrayIcon, Vertical (1).
  • Example of use: If you are using the mouse wheel, you can use the scroll (…) event to increase or decrease the volume of a player used in the main program.
  • In the download area you will find an interesting project by Gianluigi (bagonergi@gmail.com), where the icon is alternatively changed via the scroll (…) event. This calls up a different context menu for different icons.

In chapter 13.6 Context menu - TrayIcon you will find a project that uses selected properties, methods and events of the class TrayIcon.

19.2.2 Class TrayIcons

This class implements a virtual collection of all TrayIcon objects managed by an application. This class behaves like a read-only class.

Dim hTrayIcon As TrayIcon
hTrayIcon = TrayIcons [ Index As Integer ]

All TrayIcon objects can be iterated with the keyword pair “For Each”:

Dim hTrayIcon As TrayIcon
For Each hTrayIcon In TrayIcons
...
Next

While the TrayIcons.Count property returns the number of TrayIcon objects managed by an application, the only method TrayIcons.DeleteAll () of the TrayIcons class deletes all TrayIcon objects.

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k19/k19.2/start.txt · Last modified: 13.10.2023 by emma

Page Tools