Custom Designer for a Control

MysticEarth picture MysticEarth · Feb 9, 2010 · Viewed 7.3k times · Source

I've got a custom class which derives from SplitContainer:

namespace Builder.Components
{
    public partial class ProjectSidebar : SplitContainer
    {
        public ProjectSidebar()
        {
            InitializeComponent();
        }
    }
}

Now when I right-click and select View Designer I'd like to see the SplitContainer and edit it, like I would with the default controls (drop a panel in it, etc.). All I see is a message to add controls and switch to Code view.

How to achieve this?

Answer

Jeff Yates picture Jeff Yates · Feb 9, 2010

In order to add design-time functionality like additional operations (known as Action Lists and Verbs depending on how they are provided), or dragging of visual elements like headers or split bars, you need to implement a custom designer (usually derived from ControlDesigner) that allows the Windows Forms designer to understand how to interact with your custom control at design-time.

MSDN has a lengthy section on adding design-time support for your controls. It describes everything from type converters to extender providers and designer serialization to designer customization.

Additional resources

This article on CodeProject contains information on creating designers for custom controls. There are also some useful tips here and in this other StackOverflow question.