C# 表单应用程序未关闭面板的用户控件
我创建了一个主窗体(MainImagincup)和两个面板(panel,panel2)。 以及在面板中显示的用户控件2。 我使用此代码来显示:
Number_Eng_Ban jk = new Number_Eng_Ban();
jk.Show();
panel2.Controls.Add(jk);
这段代码要删除:
MainImaginCp pk = new MainImaginCp();
Number_Eng_Ban jk = new Number_Eng_Ban();
pk.panel2.Controls.Clear();
pk.panel2.Controls.Remove(jk);
但它并没有从主窗体中删除。我能做什么?
I have created one main form(MainImagincup) with two panels(panel,panel2).
And an usercontrol to show in the panel2.
I have used this code to show :
Number_Eng_Ban jk = new Number_Eng_Ban();
jk.Show();
panel2.Controls.Add(jk);
And this code to remove:
MainImaginCp pk = new MainImaginCp();
Number_Eng_Ban jk = new Number_Eng_Ban();
pk.panel2.Controls.Clear();
pk.panel2.Controls.Remove(jk);
But it is not removing from the main form . What I can do ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您调用
pk.panel2.Controls.Remove(jk);
时,jk 被充分引用?在我看来,当您退出将其添加到面板的方法时,jk 会被清除。
您应该尝试在您的类中声明
Number_Eng_Ban jk;
,然后(当您想要添加它时)执行jk = new Number_Eng_Ban();
jk is well-referenced when you call
pk.panel2.Controls.Remove(jk);
?It seems to me that jk is cleared when you exit method in which you add it to the panel.
You should try to declare
Number_Eng_Ban jk;
in your class, then (when you want to add it) dojk = new Number_Eng_Ban();