我用的是C#2005,为了控制版面,要做个类似于母版的用户控件,里面放置若干个Panel,希望在其他页面使用这个控件时,可以往Panel里放置自己需要的控件。
但现在用户控件里的Panel根本无法再往里面放东西。请问可以用什么控件来替代Panel,实现我的要求?母版也许可以实现我的要求,不过我还是希望能解决上面的疑问。
但现在用户控件里的Panel根本无法再往里面放东西。请问可以用什么控件来替代Panel,实现我的要求?母版也许可以实现我的要求,不过我还是希望能解决上面的疑问。
调试欢乐多
会把这个usercontrol里的panel包装成一个新的控件后成为form的一个控件去控制
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");
}
}
}