publicpartialclassForm1:Form { publicForm1() { InitializeComponent(); } Form2f; privatevoidbutton1_Click(objectsender,EventArgse) { if(f==null)//如果子窗体为空则创造实例并显示 { f=newForm2()
; f.StartPosition=FormStartPosition.CenterScreen;//子窗体居中显示 f.Show(); } else { if(f.IsDisposed)//若子窗体关闭则打开新子窗体并显示 { f=newForm2()
; f.StartPosition=FormStartPosition.CenterScreen;//子窗体居中显示 f.Show(); } else{ f.Activate()
;//使子窗体获得焦点 } } }}