New to Telerik UI for WinForms? Download free 30-day trial

ContextMenu

You can display a context menu when the user interacts with the notify icon with the help of the TrayContextMenu property.

TrayContextMenu

The TrayContextMenu property expects a value of type RadContextMenu. Example 1 demonstrates how it can be used.


void SetContextMenu()
{
    RadNotifyIcon radNotifyIcon = new RadNotifyIcon();
    radNotifyIcon.TrayIcon = new System.Drawing.Icon("../../WinForms128x28.ico");
    radNotifyIcon.ContextMenuActivationMouseEvent = MouseActivationEvent.RightClick;
    radNotifyIcon.ShowTrayIcon = true;
    radNotifyIcon.PopupContent = new UserControl1();          
    var contextMenu = new RadContextMenu();
    contextMenu.Items.Add(new RadMenuItem("Item 1"));
    contextMenu.Items.Add(new RadMenuItem("Item 2"));
    contextMenu.Items.Add(new RadMenuItem("Item 3"));
    radNotifyIcon.TrayContextMenu = contextMenu;
}


Private Sub SetContextMenu()
    Dim radNotifyIcon As RadNotifyIcon = New RadNotifyIcon()
    radNotifyIcon.TrayIcon = New System.Drawing.Icon("../../WinForms128x28.ico")
    radNotifyIcon.ContextMenuActivationMouseEvent = MouseActivationEvent.RightClick
    radNotifyIcon.ShowTrayIcon = True
    radNotifyIcon.PopupContent = New UserControl1()
    Dim contextMenu = New RadContextMenu()
    contextMenu.Items.Add(New RadMenuItem("Item 1"))
    contextMenu.Items.Add(New RadMenuItem("Item 2"))
    contextMenu.Items.Add(New RadMenuItem("Item 3"))
    radNotifyIcon.TrayContextMenu = contextMenu
End Sub


Figure 1: RadContextMenu displayed over the icon

RadContextMenu displayed over the icon

ContextMenuActivationMouseEvent

The ContextMenuActivationMouseEvent property determines when the context menu will be shown. The default value is RightClick. This property is enumeration and it expose the following values:

  • LeftClick: Triggered on left mouse click.
  • RightClick: Triggered on right mouse click.
  • MiddleClick: Triggered on middle mouse click.
  • LeftDoubleClick: Triggered on left mouse double click.
  • RightDoubleClick: Triggered on right mouse double click.
  • MiddleDoubleClick: Triggered on middle mouse double click.
  • All: Triggered on any mouse click action.

radNotifyIcon.ContextMenuActivationMouseEvent = MouseActivationEvent.MiddleClick;


radNotifyIcon.ContextMenuActivationMouseEvent = MouseActivationEvent.MiddleClick


In this article