C# WinForm中,如何判断窗口已打开?
1个回答
展开全部
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Form2 f;
private void button1_Click(object sender, EventArgs e)
{
if (f == null) //如果子窗体为空则创造实例 并显示
{
f = new Form2();
f.StartPosition = FormStartPosition.CenterScreen;//子窗体居中显示
f.Show();
}
else
{
if (f.IsDisposed)//若子窗体关闭 则打开新子窗体 并显示
{
f = new Form2();
f.StartPosition = FormStartPosition.CenterScreen;//子窗体居中显示
f.Show();
}
else {
f.Activate(); //使子窗体获得焦点
}
}
} }
{
public Form1()
{
InitializeComponent();
}
Form2 f;
private void button1_Click(object sender, EventArgs e)
{
if (f == null) //如果子窗体为空则创造实例 并显示
{
f = new Form2();
f.StartPosition = FormStartPosition.CenterScreen;//子窗体居中显示
f.Show();
}
else
{
if (f.IsDisposed)//若子窗体关闭 则打开新子窗体 并显示
{
f = new Form2();
f.StartPosition = FormStartPosition.CenterScreen;//子窗体居中显示
f.Show();
}
else {
f.Activate(); //使子窗体获得焦点
}
}
} }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询