You can add a Panel into the UserControl and dock it to fill in the UserControl;then create a custom ControlDesigner class to call the EnableDesignMode method to enable dragging controls to the panel at design time, the following sample demonstrates how to do this:
Code Block
Designer(typeof(myControlDesigner))]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.innerPanel = new Panel();
this.innerPanel.Dock = DockStyle.Fill;
this.Controls.Add(this.innerPanel);
}
private Panel innerPanel;
public Panel InnerPanel
{
get { return innerPanel; }
set { innerPanel = value; }
}
}
class myControlDesigner : ControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);
UserControl1 uc = component as UserControl1;
this.EnableDesignMode(uc.InnerPanel, "Panel");
}
}
You can add a Panel into the UserControl and dock it to fill in the UserControl;then create a custom ControlDesigner class to call the EnableDesignMode method to enable dragging controls to the panel at design time, the following sample demonstrates how to do this:
Code Block
Designer(typeof(myControlDesigner))]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.innerPanel = new Panel();
this.innerPanel.Dock = DockStyle.Fill;
this.Controls.Add(this.innerPanel);
}
private Panel innerPanel;
public Panel InnerPanel
{
get { return innerPanel; }
set { innerPanel = value; }
}
}
class myControlDesigner : ControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);
UserControl1 uc = component as UserControl1;
this.EnableDesignMode(uc.InnerPanel, "Panel");
}
}
I found the solution, just add this in the top of the code (tested in vb.net 2005)
Imports System.ComponentModel
Imports System.ComponentModel.Design
<Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(IDesigner))> _
Public Class .....
your code .....
End Class |