)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to associate a WinForms PopupMenu with a control for context menu-like behavior?

Platform: WinForms |
Control: XPToolbar |
Published Date: April 30, 2011 |
Last Revised Date: February 7, 2020

Context menu

The PopupMenusManager lets you easily associate a PopupMenu with a control:

Through Designer

Once you drop a PopupMenusManager onto your form, you will see an extended "ContextMenu" property on all your controls. Set the property to the PopupMenu you just created. This will show the popup menu whenever you right-click on the control during run-time. If you want to show a popup menu during some other event, read below for instructions to manually display the popup.

Through Code

You can use the PopupMenusManager to associate a PopupMenu with a control as follows:

C#

this.popupMenusManager1.SetContextMenu(this.treeViewAdv1, this.popupMenu1);

VB

Me.popupMenusManager1.SetContextMenu(Me.treeViewAdv1, Me.popupMenu1)

Instead, you could show the popup menu manually, as follows:

C#

private void MouseClickedHandler(object sender, System.Windows.Forms.MouseEventArgs e)
{
   if(e.Button == MouseButtons.Right)
      this.popupMenu1.Show((Control)sender, new Point(e.X, e.Y));
}

VB

Private Sub TreeViewAdv1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeViewAdv1.MouseClick
   If e.Button = Windows.Forms.MouseButtons.Right Then
      Me.PopupMenu1.Show(CType(sender, Control), New Point(e.X, e.Y))
   End If
End Sub

Sample: http://help.syncfusion.com/support/samples/kb/Tools.Windows/Tppmanager/Popupmanager.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon