Version

Display a Menu as a Context Menu

Sometimes you need to display a context menu when the user right-clicks on a form or any of the controls contained on that form. The WinToolbarsManager™ gives you the option of using its PopUpMenu tool for this behavior once the element is added to the form.

To display a menu as a context menu at design-time:

  1. Add the UltraToolBarsManager to a form, right click and choose Customize.

  2. In the editor create a toolbar and a PopUpMenu tool along with some Button tools.

  3. Drag the Menu tool onto the toolbar and then drag the Button tools onto the menu’s drop down.

  4. Either drag the PopUpMenu off the toolbar or set its Visible property to False.

  5. Select the form or any of its child controls and in the property page, find the "ContextMenuUltra on ultraToolbarsManager" property and select it. In the drop down, which will list all the PopUpMenu tools that are defined in the Manager with their keys listed. Select the PopUpMenu tool you just created.

  6. Run the project, right click the form, and the PopUpMenu tool will be displayed.

To display a menu as a context menu at run-time use the following code.

In Visual Basic:

Private Sub Display_a_Menu_as_a_Context_Menu_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
	Me.UltraToolbarsManager1.SetContextMenuUltra(Me, "PopUpMenuTool1")
End Sub

In C#:

private void Display_a_Menu_as_a_Context_Menu_Load(object sender, EventArgs e)
{
	this.ultraToolbarsManager1.SetContextMenuUltra(this,"PopUpMenuTool1");
}