Steve98796

I have created a class for a control. I have tried deriving the class from UserControl, ContainerControl or an existing control and the following issue applies to all.

The class I have created for a control contains a Panel docked at the top.

When I use this control on a form in the VS designer, the control appears ok with the child panel docked at the top.

Now I want to use the designer to add another control as a child of my control and dock this to the top but below the Panel that is added in the class of the control.

However the designer always adds it above the existing Panel presumably because the Panel hasnt been added directly by the designer but is part of the derived control.

Is there any way to get the controls i subsequently dock to the top to be below the Panel contained in the derived control.

Thanks

Steve



Re: Windows Forms General Derived Control child docking

nobugz

For docking to work properly, the order in which the controls get added to the Controls collection is important. You can't fully control that in the designer, the Panel always get added first. You can change the order at runtime:

private void UserControl1_Load(object sender, EventArgs e) {
panel1.SendToBack();
}






Re: Windows Forms General Derived Control child docking

Steve98796

Hi NoBugz

Thanks for the reply.

Thats solves the problem but it makes it difficult when designing and adding controls to the panel to see where they are.

Is there any way to create your own control which has a panel docked at the top which can then be used in the VS designer so that the designer sees the panel docked at the top

What I am trying to do is create my own panel which has a a graphic across the top which I can reuse many times without placing the graphic each time. I ten want to place this use derived panel on forms and add further controls the main body of the panel but docked to the top below the graphic.

Thanks

Steve





Re: Windows Forms General Derived Control child docking

nobugz

It docked properly in the designer, which rather surprised me. I used the ParentControlDesigner, what are you using





Re: Windows Forms General Derived Control child docking

Steve98796

I have tried various combinations but currently my control is derived from UserControl and yes uses ParentControlDesigner.

However, having played around further this I found this helps.

I place a new panel on my control and set DockStyle to Top. This makes it go above my existing panel set in my control definition.

If I now right click and select Bring to Front, it moves to correct place underneath the other panel, albeit this lasts only temporarily and I still need the code to above at runtime but this is manageable.

One other approach I tried which is causing another problem is as foolows:

On the control, as well as the top panel, I create and place another panel underneath it with dockstyle set to Fill. So i have my graphic panel and the top and another panel for content underneath this.

However, now when I use this control in the designer and try to place a control on the main second panel, controls are not added to the main panel but to the control itself.

So my user control is say MyControl which contains a panel docked at the top called TopPanel and a panel docked to fill called MainPanel.

When I place MyControl on a form all appears ok. If I now try to place say a label on the control in the MainPanel area the designer creates code to add it to MyControl not to MainPanel. Is there a way to achieve this as it would resolve the original problem.

Thanks

Steve





Re: Windows Forms General Derived Control child docking

nobugz

You'd better start a thread in the Windows Forms Designer forum.





Re: Windows Forms General Derived Control child docking

Steve98796

Ok



Re: Windows Forms General Derived Control child docking