Custom Controls Design Time Support Part 11: Designer Verbs

by Amr Elsehemy 26. January 2008

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.

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
{
    get
    {
        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;
    Control.Refresh();
}
private void MakeGreenBorder(object sender, EventArgs e)
{
    _pen.Color = Color.Green;
    Control.Refresh();
}
private void MakeBlueBorder(object sender, EventArgs e)
{
    _pen.Color = Color.Blue;
    Control.Refresh();
}

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: http://msdn2.microsoft.com/en-us/library/xfk1zfw9.aspx

Currently rated 5.0 by 6 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Design Time Support

Comments

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Amr Elsehemy
MCSD C#.Net,
MCTS Sql 2005,
MCPD Enterprise
avatar
E-mail me Send mail

Sponsors


Calendar

<<  July 2009  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar