我在一个按钮中加载了一个自定义控件,可是我在另一个按钮中删除不了这个自定义控件。
privatevoidnavBarItem1_LinkClicked(objectsender,DevExpress.XtraNavBar.NavBarLinkEvent...
private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
customer_info UCtrl = new customer_info();
UCtrl.Location = new Point(0,0);
this.splitContainerControl1.Panel2.Controls.Add(UCtrl);
}
private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
customer_info UCtrl = new customer_info();
this.splitContainerControl1.Panel2.Controls.Remove(UCtrl);
} 展开
{
customer_info UCtrl = new customer_info();
UCtrl.Location = new Point(0,0);
this.splitContainerControl1.Panel2.Controls.Add(UCtrl);
}
private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
customer_info UCtrl = new customer_info();
this.splitContainerControl1.Panel2.Controls.Remove(UCtrl);
} 展开
2个回答
展开全部
移除不了是因为你移除的不是你刚才添加的那个控件。简单的说就是你创建了两个自定义控件的实例,添加的是一个,移除的是另一个。你在两个按钮的click事件中都new了一个自定义控件,这就是两个不同的实例。如果你想将添加的控件移除,就应该将这个控件的实例申明为全局的,而不是局部的。
customer_info UCtrl ;//申明全局的自定义控件实例
private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
UCtrl = new customer_info();
UCtrl.Location = new Point(0,0);
this.splitContainerControl1.Panel2.Controls.Add(UCtrl);
}
private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
this.splitContainerControl1.Panel2.Controls.Remove(UCtrl);
}
customer_info UCtrl ;//申明全局的自定义控件实例
private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
UCtrl = new customer_info();
UCtrl.Location = new Point(0,0);
this.splitContainerControl1.Panel2.Controls.Add(UCtrl);
}
private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
this.splitContainerControl1.Panel2.Controls.Remove(UCtrl);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询