Live Chat Icon For mobile
Live Chat Icon

How do I add a context menu to a control

Platform: WinForms| Category: Menus

The frame will manage a context menu for you if you set the control’s ContextMenu property. Here is some code adding a context menu to a Label.

	//Add Menus in your form’s constructor...
	this.pictureContextMenu = new ContextMenu();
	this.pictureContextMenu.MenuItems.Add('&Color', 
			new EventHandler(Color_Clicked));
	this.pictureContextMenu.MenuItems.Add('&Font', 
			new EventHandler(Font_Clicked));
	label1.ContextMenu = this.pictureContextMenu;
	//
	// TODO: Add any constructor code after InitializeComponent call
	//
          }
	
          private void Font_Clicked(object sender, System.EventArgs e) 
          {     . . .     }

          private void Color_Clicked(object sender, System.EventArgs e) 
         {  ...       }

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.