以下的代码只能打开一次,我想做到关闭之后,单击又能再次打开,请问怎么做?望各路大神指点迷津。谢谢
bool IsPress=false;
private void btn_user_Click(object sender, EventArgs e)
{
if (!IsPress)
{
this.IsMdiContainer = true; //设置父窗体是容器
UserNameForm userform = new UserNameForm(); //实例化子窗体
userform.MdiParent = this; //设置窗体的父子关系
userform.Parent = panel3; //设置子窗体的容器为父窗体中Panel
userform.Show(); //显示子窗体
IsPress = true;
}
}
把你代码中的IsPress变量设为全局变量,然后在子窗体初始化时设置 IsPress = true;
子窗体onclosing事件中设置 IsPress =false 就可以了
囧,你的IsPress在单击的情况下已经赋值为了True了,以后再单击的时候,这个状态就是true所以不会执行到你的代码位置,你可以在子窗体关闭的时候,
将IsPress设置为False,这样就行了
IsPress = true;去掉就可以了。