使用c#调用第二个表单时我无法处理第一个表单

时间:2017-05-16 05:32:41

标签: c#

如何在使用c#调用第二个表单时处理第一个表单,这是我的代码:

Form2 f2 = new Form2();
f2.Show();
this.Dispose();

3 个答案:

答案 0 :(得分:1)

当您运行命令readFile('./notes.txt') .then(txt => console.log(txt)) .catch(...); 时,您将从new Form2()创建一个新的Form实例作为子元素。因此,您无法处置父代Form1(代码中为Form1)。

答案 1 :(得分:1)

如果您处理主表单,申请将会关闭。

试试此代码

this.Visible = false;

Form2 f2 = new Form2();

f2.ShowDialog();

this.Visible = true;

只要Form2处于打开状态,这只会隐藏主窗体。

答案 2 :(得分:0)

为什么要尝试处理主窗体,而不是隐藏第一个窗体:

Form2 f2 = new Form2();

f2.Show();   //It shows the new form(Second Form)

this.Hide(); //It hides the current form

它会隐藏主窗体并显示第二个窗体。