Windows User Management Library in C #

How can I implement small task functions in my own custom window management library as shown below? alt text

+3
source share
2 answers

You need to create your own designer for your control. Start this by adding a link to System.Design. A sample control might look like this:

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;

[Designer(typeof(MyControlDesigner))]
public class MyControl : Control {
    public bool Prop { get; set; }
}

Note the [Designer] attribute, it sets the custom constructor of the controls. To get started, get your own designer out of ControlDesigner. Override the ActionLists property to create a task list for the designer:

internal class MyControlDesigner : ControlDesigner {
    private DesignerActionListCollection actionLists;
    public override DesignerActionListCollection ActionLists {
        get {
            if (actionLists == null) {
                actionLists = new DesignerActionListCollection();
                actionLists.Add(new MyActionListItem(this));
            }
            return actionLists;
        }
    }
}

ActionListItem, :

internal class MyActionListItem : DesignerActionList {
    public MyActionListItem(ControlDesigner owner)
        : base(owner.Component) {
    }
    public override DesignerActionItemCollection GetSortedActionItems() {
        var items = new DesignerActionItemCollection();
        items.Add(new DesignerActionTextItem("Hello world", "Category1"));
        items.Add(new DesignerActionPropertyItem("Checked", "Sample checked item"));
        return items;
    }
    public bool Checked {
        get { return ((MyControl)base.Component).Prop; }
        set { ((MyControl)base.Component).Prop = value; }
    }
}

GetSortedActionItems .

. , Visual Studio , . VS2008 . . VS, .

+3

Source: https://habr.com/ru/post/1774993/


All Articles