其实是窗口间通讯的问题
实现方法:
在子窗口中声明事件:
public event childclose closefather;
然后在它的关闭事件中触发本事件:
private void Form1_Closed(object sender, System.EventArgs e)
{
//用事件去关闭主窗口
closefather();
}
或者用这样的方法,使用模式窗体,当子窗体传回一个特定的值的时候,决定父窗体的动作
(个人理解,比较简单的实现方法,但是,上述方法,可以锻炼一下代理和事件的使用)
在父窗口中(登陆窗口中):
在窗口类之前,在共同的命名空间之后声明代理:
public delegate void childclose();
然后弹出子窗体的地方这样写:
Form1 ff=new Form1();
ff.closefather+=new childclose(this.closethis);
//closethis()是父窗体中的一个方法
ff.Show();
定义方法:
public void closethis()
{
this.Close();
}
完!
转载于:https://www.cnblogs.com/w84717/archive/2008/06/07/1215443.html