简体   繁体   English

表单隐藏在Visual Studio中不起作用

[英]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. 确切地写了什么。

  1. A button on an existing Login form is clicked 单击现有Login表单上的按钮
  2. A new Login from is created and stored into login_f variable. 创建一个新的Login from,并将其存储到login_f变量中。
  3. A new Interface from is created and stored into interface_f variable. 创建一个新的Interface from,并将其存储到interface_f变量中。
  4. 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.

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