Custom Controls Design Time Support Part 11: Designer Verbs

This post is simple and neat, the goal now is to add some designer verbs, so lets get straight.

What is a Designer Verb?

A designer can use the DesignerVerb class to add menu commands to the shortcut menu for the component it provides designer support for in design mode. Designer verbs associate a menu item with an event handler. Designer verbs are provided to the design-time environment by the Verbs property of the IDesigner interface. [more]

How to add Designer Verbs?v

I will use the sample I introduced in the last post, I have a TestUserControl that has a red dotted border , and a ShowBorder property to show or hide that border, now I will add on the UserControlDesigner class some verbs ( menu items ) to change the color of the Border ( in case if we had a from with red background so the border will be lost ).


public override DesignerVerbCollection Verbs
        return new DesignerVerbCollection(
            new DesignerVerb[]
                new DesignerVerb("Make Border Red",new EventHandler(MakeRedBorder)),
                new DesignerVerb("Make Border Green",new EventHandler(MakeGreenBorder)),
                new DesignerVerb("Make Border Blue",new EventHandler(MakeBlueBorder)),

private void MakeRedBorder(object sender, EventArgs e)
    _pen.Color = Color.Red;
private void MakeGreenBorder(object sender, EventArgs e)
    _pen.Color = Color.Green;
private void MakeBlueBorder(object sender, EventArgs e)
    _pen.Color = Color.Blue;


v2Where will they appear?

The verbs will have to places to appear now.

1. In the context menu on the control, on right click.

2. In the Property window when the control is selected, but make sure that the commands is enabled in the property window.

More from msdn:







One response to “Custom Controls Design Time Support Part 11: Designer Verbs”

  1. daniel Avatar

    Thank you, this is an excellent series!


Leave a Reply

Your email address will not be published. Required fields are marked *