定义了一个用户控件UserControl1,该控件中有一个Panel,其中Panel声明为Public,
在UserControl1前定义了特性 [System.ComponentModel.Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design ")],
此时UserControl1可以在设计时接受拖放进来的控件,而其中的Panel确不能,
现在我想让UserControl1中的Panel在设计时也可以将其他控件拖入到其中,如何作到这一点呢?
如果不明白我的意思,可以下载我上传的例程:http://g.zhubajie.com/urllink.php?id=5016607uhhkiqhqvbiwgr94
其中紫色部分是Panel。

解决方案 »

  1.   

    ascx达不到这个效果,用自定义控件
      

  2.   

    这个用户控件不要继承UserControl,继承Panel,在代码里添加你要加入的其它控件。
    public partial class UserPanelCon : Panel
        {
            public UserPanelCon () {
                InitializeComponent();
                AddControl();
            }        protected void AddControl () {
                Button btn = new Button();
                btn.Text = "new";
                btn.Location = this.Location;
                btn.Width = 100;
                btn.Height = 50;
                this.Controls.Add(btn);
            }
        }