简体   繁体   English

使用VC#GUI表单

[英]Working with VC# GUI Forms

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 - 嗨,我是一名新程序员,我只是想知道为什么我们不能在以下代码的帮助下关闭隐藏的VC#表单-

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. 请告诉我为什么我们不能在Form1的新实例的帮助下关闭和隐藏当前表单。

Your code is trying to close and hide the new form, not the current one. 您的代码正在尝试关闭和隐藏表单,而不是当前表单。

this.Close();

means to close the current form. 表示关闭当前表格。

You can't close the new form before you have even shown it. 在显示新表单之前,您无法关闭它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM