开发者

Custom Designer for a Control

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 SplitContaine开发者_运维百科r 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?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜