- 控件的克隆,复制,动态加载控件 下面是扩展方法,需要单独创意一个ControlExtensions扩展,然后就可以.出来了。具体的克隆是克隆一个完全一模一样的空间,但是如果是panel,需要对panel进行递归。但是还不清楚为什么panel克隆一次就被清空了,正在研究中。
//克隆面板,并决定他的位置
Panel new_p = p_Reserve.Clone()
new_p.Name = "p_iReserve"
new_p.Size = new System.Drawing.Size(p_Reserve.Size.Width, 230)
new_p.Location = new Point(p_Reserve.Location.X, count * 31)
GroupBox c_group = new GroupBox()
TextBox c_text = new TextBox()
Label c_label = new Label()
RichTextBox c_rich = new RichTextBox()
Button c_btn = new Button()
//循环面板里面的空间进行克隆
for (int i = 0
{
Control ctrl = p_Reserve.Controls[i]
if (ctrl.GetType() == typeof(System.Windows.Forms.GroupBox))
{
c_group = (GroupBox)ctrl
c_group.Visible = true
}
new_p.SendToBack()
new_p.Visible = true
new_p.Parent = p_Main
}