Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm making a custom control using C#, and I need to add a link to the property box(so I can show a form once it's clicked).

Here's an example:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
301 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...