问题描述
我在C#中有三个表单,主要表单是A,第二个是B&第三个是C.我想使用按钮从主表单关闭B&C两个表单(如果B&C被激活)。
I have three form in C#, main form is A, second is B & third is C. I want to close B&C both form (if B&C are activated) from main form using a button.
推荐答案
B FormBInstance = new B();
C FormCInstance = new C();
表格显示如下:
private void MainForm_Load(object sender, EventArgs e)
{
FormBInstance.Show();
FormCInstance.Show();
}
然后Button Click EventHandler可能如下所示:
Then the Button Click EventHandler might look like this:
private void CloseBC_Click(object sender, EventArgs e)
{
if (FormBInstance != null) FormBInstance.Close();
if (FormCInstance != null) FormCInstance.Close();
CloseBC.Enabled = false;
}
我认为如果某些用户界面控件不再执行它应该被禁用...或隐藏的话,这是个好主意。
但是,请记住,一旦关闭Form的任何实例:所有数据,用户与Form上的Controls交互的所有结果都是:lost。
I think it's a good idea that if some user-interface Control no longer "does" anything it should be disabled ... or hidden.
But, do keep in mind that once you "close" any instance of a Form: all data, all the results of user interactions with the Controls on the Form, are: lost.
这篇关于我在C#中有三种形式,主要形式是A,第二种是B&第三个是C.我想使用一个按钮从主表单中关闭B& C两种形式(如果B& C被激活)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!