all groups > dotnet windows forms designtime > june 2004 >
You're in the

dotnet windows forms designtime

group:

Adding custom verbs for other controls on form in designer


Adding custom verbs for other controls on form in designer Bill Henning
6/22/2004 7:23:46 AM
dotnet windows forms designtime:
Does anyone know if it is possible to add verbs in the designer to controls
that are NOT created by me? For instance, whenever the user has an instance
of one of my manager components on their form and selects a control (such as
a Button, Label, or any other control not created by me), I would like to
add a verb "Do Something" to that Control's context menu and have it visible
in the verb area in the property grid.

Is this possible? I believe Infragistics does this with their controls but
I haven't found any help on how to implement it.

Thanks for your help.

Bill

Re: Adding custom verbs for other controls on form in designer jmghost NO[at]SPAM msn.com
6/23/2004 4:53:47 PM
Hi Bill,

I'm doing something like this in my custom controls designer
I didn't try compiling it but I just modified it from some of my code
so hopefully it works.

private DesignerVerb SomeVerb;

public override void Initialize(IComponent component)
{
base.Initialize (component);

ISelectionService ss =
(ISelectionService)GetService(typeof(ISelectionService));

if (ss != null)
ss.SelectionChanged += new EventHandler(OnSelectionChanging);

this.SomeVerb = new DesignerVerb("Invoke SomeVerb", new
EventHandler(SomeVerbHandler));
}

public void OnSelectionChanging(object sender, EventArgs e)
{
ISelectionService ss =
(ISelectionService)GetService(typeof(ISelectionService));

if( ss.PrimarySelection is Button ||
ss.PrimarySelection is Label
{
IDesignerHost dh = (IDesignerHost)
this.GetService(typeof(IDesignerHost));
IDesigner dsgnr = (IDesigner)dh.GetDesigner(
(Control)ss.PrimarySelection );

if( !dsgnr.Verbs.Contains() )
dsgnr.Verbs.Add(SomeVerb);
}
}

private void SomeVerbHandler(object sender, EventArgs e)
{
MessageBox.Show("Do Something");
}

kind regards,
Jerron



[quoted text, click to view]
Re: Adding custom verbs for other controls on form in designer Bill Henning
6/24/2004 6:27:21 PM
Thanks Jerron... that works!


[quoted text, click to view]

AddThis Social Bookmark Button