我用的是C#2005,为了控制版面,要做个类似于母版的用户控件,里面放置若干个Panel,希望在其他页面使用这个控件时,可以往Panel里放置自己需要的控件。
但现在用户控件里的Panel根本无法再往里面放东西。请问可以用什么控件来替代Panel,实现我的要求?母版也许可以实现我的要求,不过我还是希望能解决上面的疑问。

解决方案 »

  1.   

    用EnableDesign ,很早前回答过,不过忘了,而且例子是参照一国外网站的,虽然不是很完美,你还是google搜一下把
    会把这个usercontrol里的panel包装成一个新的控件后成为form的一个控件去控制
      

  2.   

    楼上的各位老大,网上我去搜了下C# web下使用groupbox的例子,实在太少了,各位有什么现成的教程没?
      

  3.   

    我找到那段代码了不过是winform的
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Windows.Forms.Design; // 在这里using前要先添加引用“System.Design”namespace WindowsControlLibrary2
    {
        [Designer(typeof(UserControlDesigner))]
        public partial class UserControl1 : UserControl
        {
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public Panel ContentArea
            {
                get
                {
                    return panel1; // 在上面放一个Panel,名字叫 panel1
                }
            }        public UserControl1()
            {
                InitializeComponent();            // 我这里的设置只是让panel更醒目点
                this.Size = new Size(700, 700);
                this.BackColor = Color.Gray;
                panel1.Size = new Size(500, 500);
                panel1.ForeColor = Color.Black;
                panel1.Parent = this; 
            }        private void panel1_ControlAdded(object sender, ControlEventArgs e)
            {
                e.Control.Parent = panel1;
            }
        }    public class UserControlDesigner : ControlDesigner
        {
            public override void Initialize(System.ComponentModel.IComponent Ic)
            {
                base.Initialize(Ic);
                UserControl1 UC = (UserControl1)Ic;
                EnableDesignMode(UC.ContentArea, "ContentArea");
            }
        }
    }
      

  4.   

    wartim对Designer的了解很强悍阿,哈哈!有空多交流!