[英]Form hide doesn't work in Visual Studio
I just started Visual Studio and I tried opening another form using a button and it worked well but the hide code to hide the first form doesn't seem work. 我刚启动Visual Studio并尝试使用按钮打开另一个表单,但效果很好,但是隐藏第一个表单的隐藏代码似乎无效。 Here's my code (Login = form1, Interface = form2):
这是我的代码(登录= form1,接口= form2):
private void login_button_Click(object sender, EventArgs e)
{
Login login_f = new Login();
Interface interface_f = new Interface();
login_f.Hide();
interface_f.Show();
}
What is going on: 到底是怎么回事:
Exactly what's been written. 确切地写了什么。
Login
form is clicked Login
表单上的按钮 Login
from is created and stored into login_f
variable. Login
from,并将其存储到login_f
变量中。 Interface
from is created and stored into interface_f
variable. Interface
from,并将其存储到interface_f
变量中。 interface_f
becomes visible, login_f
form becomes invisible. interface_f
变为可见, login_f
表单变为不可见。 The very first form which has been actually clicked stays the same. What to do: login_f
variable should contain reference to the clicked form. 怎么办:
login_f
变量应包含对单击的表单的引用。 This reference can be retrieved via this
keyword. 可以通过
this
关键字检索此引用。
private void login_button_Click(object sender, EventArgs e)
{
var login_f = this;
Interface interface_f = new Interface();
login_f.Hide();
interface_f.Show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.