如何从C#中的表单关闭表单?

时间:2018-01-10 22:53:55

标签: c#

我有3张表格。从Form1我用一个按钮打开Form3和Form4。但是,当我按下Form4上的按钮时,我想要关闭Form4和Form3。(不要担心Form2)

Form1中:

private void button1_Click(object sender, EventArgs e)
    {

        Form3 frm3 = new Form3();
        frm3.Show();

        Form4 frm4 = new Form4();
        frm4.Show();



    }

表格4:

private void button12_Click(object sender, EventArgs e){
    this.Close();
    //Plus close Form3

1 个答案:

答案 0 :(得分:0)

Form1中:

private void button1_Click(object sender, EventArgs e) { 
   Form3 frm3 = new Form3();
   frm3.Show(); 

   Form4 frm4 = new Form4(frm3);
   frm4.Show();
 }

Form4:

Form3 mFrm3Ref;
public Form4(Form3 frm){
    mFrm3Ref = frm;
    //and other initializing stuff 
} 
private void button12_Click(object sender, EventArgs e){
   mFrm3Ref.Close() ;
   this.Close();
}