Drag/Drop in designer into inherited panels

0
0

Thanks for your previous help.

I’ve got a issue that I think might be solvable with the right annotations or properties on my class, but can’t figure that out.

I have created a control (ControlA) which has 2 panels (PanelA and PanelB). I’ve then added this control using the visual designer to another control (WindowA).
When I am then editing WindowA and drag any controls (eg. radio buttons, textboxes,etc..) onto PanelA or PanelB, the designer adds them to ControlA, not the panels I dragged them into. The code in WindowA.designer.cs shows this.ControlA.Controls.Add().

I can manually do this.ControlA.PanelA.Controls.Add() and it’s fine. If I modify the designer.cs to do this then it gets cleared next time it’s loaded (which is expected as it regenerates it).

I have made both PAnelA and PanelB public, but I’m wondering if there is something else I need to do to make these “visible” to the designer so that it knows it should be adding the controls I drop onto it to the correct sub panels and not the parent control. Possibly some kind of property that needs to be added and/or some annotations to it to left the designer know it should add to these panels not the parent control ?

Thanks,

Andi Gordon

  • You must to post comments
0
0

FYI I couldn’t get Luca’s code to work however when I modified it by adding DesignerSerializationVisibility(DesignerSerializationVisibility.Content) Then it worked for me.

 

[Designer(typeof(TestDesigner))]
public partial class UserControl1 : Wisej.Web.UserControl
{
public UserControl1()
{
InitializeComponent();
}

[
Category(“Appearance”),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
]
public Panel WorkingArea
{
get
{
return this.panel1;
}
}

[
Category(“Appearance”),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
]
public Panel WorkingArea2
{
get
{
return this.panel2;
}
}
}

public class TestDesigner : ParentControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);

var control = (UserControl1)this.Control;
base.EnableDesignMode(control.WorkingArea, “WorkingArea”);
base.EnableDesignMode(control.WorkingArea2, “WorkingArea2”);
}
}

  • You must to post comments
0
0

I just tried, for me it puts it inside ControlA. After cleaning and recompiling you have to closed Visual Studio. The VS designer loads the designers only once.

The inner controls are not in design mode, so you cannot resize, change their properties or drop anything into a child control in a custom control. Your ControlA acts as a single block to the designer. If you want to enable child control’s design mode, you have to:

1) Make them public.

2) Enable design mode when the parent’s designer is initialized.

This is a small test I just did: It creates a Test control with a TestDesigner that enables both the control to be a parent and enables the inner Panel1 to be in design mode. Always remember to close VS and reload when changing the designer.

[Designer(typeof(TestDesigner))]
public class Test : Control
{
public Panel Panel1;

public Test()
{
this.Panel1 = new Panel()
{
Width = 100,
Height = 100,
BackColor = Color.Yellow
};

this.Controls.Add(this.Panel1);
}
}
public class TestDesigner : Wisej.Core.Design.ParentControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);

var control = (Test)this.Control;
base.EnableDesignMode(control.Panel1, “Panel1”);
}
}

 

  • You must to post comments
0
0

I added that to my ControlA class, I assume that’s where you wanted me to add it.
Rebuilt the project then opened WindowA added a control and it still put it into the ControlA parent panel, not the sub panel I put it on.

Andi

  • You must to post comments
0
0

Try to add this to your class

using System.ComponentModel;

[Designer(“Wisej.Core.Design.ParentControlDesigner, Wisej.Core.Design”)]

/Luca

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.