如何通过单击c#中的按钮来隐藏其他表单中的表单?

时间:2016-02-01 04:45:26

标签: c# winforms

 private void btnLogin_Click(object sender, EventArgs e)
    {

        Form1 frm = new Form1();
        frm.Hide();

这里form1没有隐藏,btnLogin在form2中

1 个答案:

答案 0 :(得分:7)

试试这个:

// Method in Form1 
private void button1_Click(object sender, EventArgs e)
{
    Form2 mySecondForm = new Form2(this);
    mySecondForm.Show();
}

// This is the second form which you opened from your first form..
public partial class Form2 : Form
{
    Form someForm;

    public Form2(Form parentForm)
    {
        InitializeComponent();
        someForm = parentForm;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        someForm.Hide(); // Form1 should hide now
    }
}

希望这会有所帮助。欢呼声。