How can I insert custom menu items (verbs) into my Component/Control designer’s Context Menu in design time?

Platform: WinForms| Category: Custom Designers

You need to create custom ‘Verbs’ for your Component/Control designer. This will make your ‘verbs’ show up in the property browser and in the designer context menu.

The designer throws an event when the user selects a verb and you can perform custom operation when you handle this event.

You do this by overriding the Verbs property in your Designer class.

Here is an example:


public class MyControlExtDesigner : ControlDesigner
{
	...
	public override DesignerVerbCollection Verbs 
	{ 
		get
		{
			if (this.verbs == null)
			{
				this.verbs = new DesignerVerbCollection();
				this.verbs.Add(new DesignerVerb('Add New Child',new EventHandler(this.OnAdd)));
			}
			return this.verbs;
		}
	}

	private void OnAdd(object sender, EventArgs eevent)
	{
		// Code to add a new child inside your control.
		...
	}
}

Share with

Related FAQs

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

Please submit your question and answer.