views:

90

answers:

3

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?

+1  A: 

When writing your control, you need to make sure to add design time logic to it.

See this (.NET 1.0) article on MSDN for some more details. Here is another article from 2003.

Oded
Thanks, but I can't seem to find how and which design logic to add on this specific code and how to finish creating/filling my control in the Designer...
MysticEarth
+3  A: 

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.

Jeff Yates
+1  A: 

Only the Form and the UserControl classes have designers that allow you to edit their child controls at design time. Creating your own designer to give SplitContainer the same behavior is not exactly simple, most of all because it is so poorly documented and difficult to debug. You'll need to study the framework code with Reflector to get it right.

Punt this problem, put the SplitContainer in a user control. Set its Dock property to Fill. Now it is easy.

Hans Passant