You are looking for DesignerVerb
.
A designer verb is a menu command linked to an event handler. Designer
verbs are added to a component's shortcut menu at design time. In
Visual Studio, each designer verb is also listed, using a LinkLabel,
in the Description pane of the Properties window.
You can use a verb for setting value of a single property, multiple properties or for example for just showing an about box.
Example:
Create a designer for your control or for your component deriving from ControlDesigner
class or ComponentDesigner
(for components) an override Verbs
property and return a collection of verbs.
Don't forget to add reference to System.Design.dll
.
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
[Designer(typeof(MyControlDesigner))]
public class MyControl : Control
{
public string SomeProperty { get; set; }
}
public class MyControlDesigner : ControlDesigner
{
private void SomeMethod(object sender, EventArgs e)
{
MessageBox.Show("Some Message!");
}
private void SomeOtherMethod(object sender, EventArgs e)
{
var p = TypeDescriptor.GetProperties(this.Control)["SomeProperty"];
p.SetValue(this.Control, "some value"); /*You can show a form and get value*/
}
DesignerVerbCollection verbs;
public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
if (verbs == null)
{
verbs = new DesignerVerbCollection();
verbs.Add(new DesignerVerb("Do something!", SomeMethod));
verbs.Add(new DesignerVerb("Do something else!", SomeOtherMethod));
}
return verbs;
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…