I am trying to make my own user control and have almost finished it, just trying to add some polish. I would like the option in the designer to “Dock in parent container”. Does anyone know how to do this I can’t find an example. I think it has something to do with a Docking Attribute.
Share
I order to achieve this you will need to implement a couple of classes; first you will need a custom ControlDesigner and then you will need a custom DesignerActionList. Both are fairly simple.
The ControlDesigner:
The DesignerActionList:
Finally, you will need to attach the designer to your control:
Brief explanation
The control has a
Designerattribute associated with it, which points out our custom designer. The only customization in that designer is theDesignerActionListthat is exposed. It creates an instance of our custom action list and adds it to the action list collection that is exposed.The custom action list contains a
boolproperty (DockInParent), and creates an action item for that property. The property itself will returntrueif theDockproperty of the component being edited isDockStyle.Fill, otherwisefalse, and ifDockInParentis set totrue, theDockproperty of the component is set toDockStyle.Fill, otherwiseDockStyle.None.This will display the little “action arrow” close to the upper right corner of the control in the designer, and clicking the arrow will pop up the task menu.