我的页面上有面板对象,我想用另一个面板替换它
//Info.panel[cb_page_number.SelectedIndex] = pnl_page_active;
Panel new_panel = new Panel();
new_panel.BackColor = Color.White;
//new_panel.Name ="page_"+ (cb_page_number.SelectedIndex+1).ToString();
//cb_page_number.Items.Add(new_panel.Name);
//cb_page_number.SelectedIndex = cb_page_number.Items.Count-1;
pnl_page_active = new_panel;
pnl_page_active.Refresh();
pnl_page_active.Update();
Application.DoEvents();
pnl_page_active具有象牙色的背景色,并且上面有一些控件。当我执行上面的代码时,我会看到pnl_page_active的背景已经更改,并且对此没有任何控制,但这是相同的,所以我想知道这是什么问题?
您所要做的就是将new_panel变量分配给pnl_page_active。它与控制层次结构无关。
您需要从其父面板中删除旧面板,然后插入新面板:
Control parent = pnl_page_active.Parent;
if (parent != null) {
parent.Controls.Remove(pnl_page_active);
parent.Controls.Add(new_panel);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句