<div class="meta" robots="noindex">

</div>

Class

# TrayItem

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

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

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                        | Type                                        | Read-Only | Shared |
|-----------------------------|---------------------------------------------|-----------|--------|
| `Handle<trayitem.handle>`   | `Ptr</api/data_types/additional_types/ptr>` | ✓         |        |
| `Icon<trayitem.icon>`       | `Picture</api/graphics/picture>`            |           |        |
| `ToolTip<trayitem.tooltip>` | `String</api/data_types/string>`            |           |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                      | Parameters                                  | Returns |
|---------------------------|---------------------------------------------|---------|
| `Action<trayitem.action>` | Cause As `Integer</api/data_types/integer>` |         |

## Property descriptions

<div id="trayitem.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

TrayItem.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

Returns the window handle that the <span class="title-ref">TrayItem</span> belongs to on Windows and the GtkStatusIcon widget on Linux. On Windows, the first <span class="title-ref">TrayItem</span> has a ID of 1000 and subsequent adds will increment this ID.

This property is read-only.

<div id="trayitem.icon">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

TrayItem.Icon

**Icon** As `Picture</api/graphics/picture>`

The icon displayed as the <span class="title-ref">TrayItem</span>.

<div id="trayitem.tooltip">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

TrayItem.ToolTip

**ToolTip** As `String</api/data_types/string>`

Help associated with the <span class="title-ref">TrayItem</span>.

## Event descriptions

<div id="trayitem.action">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

TrayItem.Action

**Action**(Cause As `Integer</api/data_types/integer>`)

The user has clicked on the <span class="title-ref">TrayItem</span>.

The parameter *Cause* indicates the type of click. To determine the kind of click, use the following <span class="title-ref">TrayItem</span> class constants:

| <span class="title-ref">TrayItem</span> Class Constant |
|--------------------------------------------------------|
| DoubleClick                                            |
| LeftMouseButton                                        |
| RightMouseButton                                       |

## Notes

See also the `Application.AddTrayItem<application.addtrayitem>` method for information on adding a <span class="title-ref">TrayItem</span>.

## 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:

``` xojo
Tray As AppTrayItem
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

``` xojo
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:

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

  Var result As DesktopMenuItem
  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 `DesktopApplication</api/user_interface/desktop/desktopapplication>` class. This goes in the Close event handler of the `App</api/language/app>` object.

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

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `DesktopApplication</api/user_interface/desktop/desktopapplication>` class.
