Difference between revisions of "TrayItem"

From Xojo Documentation

(Sample Code)
(Sample Code)
 
Line 38: Line 38:
 
<rbcode>
 
<rbcode>
 
Select Case cause
 
Select Case cause
Case TrayItem.PressTypes.LeftClick
+
Case TrayItem.LeftMouseButton
 
   MessageBox("Left button clicked")
 
   MessageBox("Left button clicked")
Case TrayItem.PressTypes.DoubleClick
+
Case TrayItem.DoubleClick
 
   MessageBox("Double-clicked")
 
   MessageBox("Double-clicked")
Case TrayItem.PressTypes.RightClick
+
Case TrayItem.RightMouseButton
 
   Var trayMenu As New MenuItem
 
   Var trayMenu As New MenuItem
   trayMenu.Add(New MenuItem("About"))
+
   trayMenu.AddMenu(New MenuItem("About"))
   trayMenu.Add(New MenuItem("Exit"))
+
   trayMenu.AddMenu(New MenuItem("Exit"))
   
+
 
 
   Var result As MenuItem
 
   Var result As MenuItem
 
   result = trayMenu.PopUp
 
   result = trayMenu.PopUp
   
+
 
 
   Select Case result.Text
 
   Select Case result.Text
 
   Case "About"
 
   Case "About"

Latest revision as of 14:17, 15 March 2021


Class (inherits from Object)

Used to add items to the System Tray. Windows and Linux only.

Events
Action
Properties
Handle fa-lock-32.png Icon ToolTip

Notes

See also the Application.AddTrayItem method for information on adding a TrayItem.

Sample Code

Add a class to your project (call it AppTrayItem) and change its super to TrayItem. Also add a property to the App class:

Tray As AppTrayItem

This code instantiates it in the App.Open event handler:

Tray = New AppTrayItem
If Not Self.AddTrayItem(Tray) Then
// There was an error adding the TrayItem
End If

The following code in the Action event of the AppTrayItem handles mouse clicks and double-clicks:

Select Case cause
Case TrayItem.LeftMouseButton
MessageBox("Left button clicked")
Case TrayItem.DoubleClick
MessageBox("Double-clicked")
Case TrayItem.RightMouseButton
Var trayMenu As New MenuItem
trayMenu.AddMenu(New MenuItem("About"))
trayMenu.AddMenu(New MenuItem("Exit"))

Var result As MenuItem
result = trayMenu.PopUp

Select Case result.Text
Case "About"
MessageBox("The TrayItem example")
Case "Exit"
Quit
End Select
End Select

When the application quits, you call the RemoveTrayItem method of the Application class. This goes in the Close event handler of the App object.

If Tray <> Nil Then
Self.RemoveTrayItem(Tray)
End If

See Also

Application class.