简体   繁体   English

关闭密码表格C#

[英]closing password form c#

How can I close the password form when my new form opens? 打开新表格后如何关闭密码表格?

public partial class Password : Form
{
    private string password;
    public Password()
    {
        InitializeComponent();
    }

    private void pass_TextChanged(object sender, EventArgs e)
    {
        password = "1234";
    }

    private void okButton_Click(object sender, EventArgs e)
    {
        if (passtextBox.Text == password)
        {
            list form = new list();
            form.Show();

        }
       else
        {
            MessageBox.Show("Incorrect Password. Try Again!!");
        }
    }
}

When I use this.close(); 当我使用this.close(); my new form and password form both close. 我的新表格和密码表格都已关闭。 What should I do? 我该怎么办?

I assume your PasswordForm is the main form for you which you passsed inside Application.Run method. 我假设您的PasswordForm是您在Application.Run方法内部传递的主要表单。

So when the main form closes application will exit. 因此,当主窗体关闭时,应用程序将退出。

I'd suggest you to just hide the form instead of closing it. 我建议您隐藏表格而不是关闭表格。

list form = new list();
form.Show();
this.Hide();

You can use MDI form as the parent form. 您可以使用MDI表单作为父表单。 When a new form is created and that new form(which is a child form of the MDI form) is opened over the MDI or any parent form, then you can search for all the opened child form. 创建新表单并通过MDI或任何父表单打开新表单(MDI表单的子表单)后,您可以搜索所有打开的子表单。 If any child form is found open, then close that child form. 如果找到任何子窗体,请关闭该子窗体。 In this way you can manage form opening and closing. 这样,您可以管理表单的打开和关闭。

Thanks. 谢谢。

You want to show new form and close first form if password is correct, don't you? 如果密码正确,您想显示新表格并关闭第一个表格,不是吗? Try this: 尝试这个:

 Form secondform = new form();
 Secondform.show();
 Form1 firstform = new form1();
 Firstform.hide();

i fixed it myself 我自己修好了

public partial class Password : Form { private string password; 公共部分类的密码:格式{私人字符串密码; public Password() { InitializeComponent(); 公共密码(){InitializeComponent(); } }

    private void pass_TextChanged(object sender, EventArgs e)
    {
        password = "1234";
    }

    private void okButton_Click(object sender, EventArgs e)
    {
        if (passtextBox.Text == password)
        {
         // list form = new list();
         //form.Show();
             //list secondform = new list();
              //secondform.Show();
              //Password firstform = new Password();
            // firstform.Hide();
           this.Hide();
            list sistema = new list();
            sistema.ShowDialog();
            this.Close();


        }
       else
        {
            MessageBox.Show("Incorrect Password. Try Again!!");
        }
    }




}

} }

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

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