-1

Hi I am a new programmer and i just wannna know that why can't we close an hide our VC# form with the help of following code -

private void button1_Click(object sender, EventArgs e)
{
Form1 frmobj = new Form1();
frmobj.Close();
frmobj.Hide();
}

We can do the same thing with the help of following code-

private void button1_Click(object sender, EventArgs e)
{
this.Close();
this.Hide();
}

Please tell me why can't we close and Hide the current form with the help of new instance of Form1.

4

2 回答 2

3

您的代码正在尝试关闭并隐藏表单,而不是当前表单。

this.Close();

表示关闭当前表单。

您甚至无法在显示之前关闭新表单。

于 2012-04-23T07:27:53.097 回答
0

调用 Close 方法,关闭并释放表单,这意味着在该方法调用之后,表单的实例不再存在,因此,您不能在该实例上调用任何其他成员方法,因为该实例不存在不再(被处置)。

于 2012-04-23T07:29:34.910 回答