可以如下: private void btnShowSubWin_Click(object sender, System.EventArgs e) { foreach ( Form f in this.OwnedForms ) { if (f is frmSubForm) //frmSubForm为显示子窗体类名 { f.Show(); f.Focus(); return; } }
//need a new one frmSubForm mySubForm = new frmSubForm(); this.AddOwnedForm(mySubForm); mySubForm.Owner = this; mySubForm.TopLevel=false; mySubForm.Show(); }
可以声明一个标志:
public bool form1_bool=false;
在显示新窗体时,在事件中改写标志(先判断该标志是否为false):
form1_bool=true;
:)
不好意思,上面的标志最好声明为一个静态(static)的.
private void btnShowSubWin_Click(object sender, System.EventArgs e)
{
foreach ( Form f in this.OwnedForms )
{
if (f is frmSubForm) //frmSubForm为显示子窗体类名
{
f.Show();
f.Focus();
return;
}
}
//need a new one
frmSubForm mySubForm = new frmSubForm();
this.AddOwnedForm(mySubForm);
mySubForm.Owner = this;
mySubForm.TopLevel=false;
mySubForm.Show();
}
http://expert.csdn.net/Expert/topic/1648/1648630.xml?temp=.4793054