Adding verbs to a control's design time abilities

This short example shows how to implement design-time verbs in C#

This is achieved with a ControlDesigner, like so

public class MyNameSpace.MyControlDesigner: System.Windows.Forms.Design.ControlDesigner
{
  protected override DesignerVerbCollection Verbs
  {
    get
    {
      DesignerVerbCollection result = new DesignerVerbCollection();
      result.Add(new DesignerVerb("Verb1 description", new System.EventHandler(this.OnVerb1)));
      result.Add(new DesignerVerb("Verb2 description", new System.EventHandler(this.OnVerb2)));
      return result;
    }
  }
}

The second step is to associate this designer with your control, like so

[System.ComponentModel.Designer(typeof(MyNameSpace.MyControlDesigner))]
public class MyNameSpace.MyControl: ..........
{
  etc
}

 

Share this article!

Follow us!

Find more helpful articles: