WinForms ContextMenu Overview

Updated over 6 months ago

To add context menus in your application, you can use RadContextMenu. The control is a non-visual component that sits in the component tray located below the form design surface. RadContextMenu, like RadMenu, can be themed and has Items collection that accepts RadMenuItem, RadMenuComboBoxItem, RadMenuSeparatorItem and RadMenuContextItem. You can subscribe to the Click event of each menu item and execute the desired logic.

ninja-iconThe ContextMenu component is part of Telerik UI for WinForms, a professional grade UI library with 160+ native components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.Start Free Trial

Figure 1: RadContextMenu

WinForms RadContextMenu Overview

There are two ways to attach a context menu to a given control or portion of a control:

  • For those RadControls that have a ContextMenu or RadContextMenu properties you can assign the RadContextMenu in the designer or in code.

Assigning a RadContextMenu

C#
radTreeView1.Nodes[0].ContextMenu = radContextMenu1;

The ContextMenuStrip property refers to a Windows standard control. This property drop down will not display RadMenu or RadContextMenu components that exist on the form.

  • Handle the mouse down event for the control that requires the context menu and call the RadContextMenu.Show() method.

Handling the MouseDown event

C#
void radCalendar1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        Point p = (sender as Control).PointToScreen(e.Location);
        radContextMenu1.Show(p.X, p.Y);
    }
}

Telerik UI for WinForms Learning Resources

Telerik UI for WinForms Additional Resources

See Also