Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 526
MysticEarth Avatar asked Feb 09 '10 13:02

MysticEarth


People also ask

What is a custom control?

A custom control is a rectangular area on the screen of a dynpro. They are created in Screen Painter and, like all other screen objects, have a unique name. Custom controls are used to embed controls in these areas. Controls are software components of the presentation server.

What is custom control user control?

The main difference between them- User Control is a page file with extension . ascx which can only be used within a single application or project But custom controls are assemblies(dll files) that can be used in multiple applications.

Which of the following is used to create the custom controls?

ASP.NET allows the users to create controls. These user defined controls are categorized into: User controls. Custom controls.


2 Answers

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.

like image 159
Jeff Yates Avatar answered Sep 30 '22 09:09

Jeff Yates


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.

like image 22
Hans Passant Avatar answered Sep 30 '22 09:09

Hans Passant