好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

c# 实现子窗口关闭父窗口也关闭的简单实例

实现方法:

在子窗口form2中声明事件:

public delegate void childclose();

   public event childclose closefather;

 

   然后在它的关闭事件中触发本事件:

 

    private void Form2_Closed( object sender, System.EventArgs e)

    {

     //用事件去关闭主窗口

     closefather();

    }

在父窗口form1中(比如登陆窗口中):

然后弹出子form2窗体的地方这样写:

Form2 ff= new Form2();

ff.closefather+= new childclose( this .closethis); //closethis()是父窗体中的一个方法

ff.Show();

 

  public void closethis()

  {

    this .Close();

  }

以上这篇c# 实现子窗口关闭父窗口也关闭的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

dy("nrwz");

查看更多关于c# 实现子窗口关闭父窗口也关闭的简单实例的详细内容...

  阅读:49次