To do this, you will need to implement several classes; first you need a custom ControlDesigner , and then you need a custom DesignerActionList . Both of them are quite simple.
ControlDesigner element:
public class MyUserControlDesigner : ControlDesigner
{
private DesignerActionListCollection _actionLists;
public override System.ComponentModel.Design.DesignerActionListCollection ActionLists
{
get
{
if (_actionLists == null)
{
_actionLists = new DesignerActionListCollection();
_actionLists.Add(new MyUserControlActionList(this));
}
return _actionLists;
}
}
}
Constructor List:
public class MyUserControlActionList : DesignerActionList
{
public MyUserControlActionList(MyUserControlDesigner designer) : base(designer.Component) { }
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
items.Add(new DesignerActionPropertyItem("DockInParent", "Dock in parent"));
return items;
}
public bool DockInParent
{
get
{
return ((MyUserControl)base.Component).Dock == DockStyle.Fill;
}
set
{
TypeDescriptor.GetProperties(base.Component)["Dock"].SetValue(base.Component, value ? DockStyle.Fill : DockStyle.None);
}
}
}
Finally, you will need to attach the constructor to your control:
[Designer("NamespaceName.MyUserControlDesigner, AssemblyContainingTheDesigner")]
public partial class MyUserControl : UserControl
{
Brief explanation
The control has an attribute associated with it Designer, which is indicated by our custom constructor. The only setting in this designer is DesignerActionListwhich is displayed. It creates an instance of our custom action list and adds it to the open action list collection.
bool (DockInParent) . true, Dock DockStyle.Fill, false, DockInParent true, Dock DockStyle.Fill, DockStyle.None.
" " , .