窗口打开问题
我想通过form1的Button去打开form2,,点击Butoon后,出现Form2窗口。不关闭form2,而再次点击Button,将不能出现第二个form2实例,也就是第二个form2窗口。而关闭form2后,才能再次出现Form2窗口,,我不知道如何判断。代码怎么写了?望不吝赐教!!
public Form1
{
Button1.click()
{
Form2 df = new Form2()???
how to coding????????????
}
}
------解决方案--------------------
你试试这个,应该可以的,我测试过了
private Form2 frm2;
private void button1_Click(object sender, EventArgs e)
{
if (frm2 == null || frm2.IsDisposed)
{
frm2 = new Form2();
frm2.Show();
}
else
{
frm2.Activate();
frm2.WindowState = FormWindowState.Normal;
}
}
------解决方案--------------------楼上这个可行
C# code
private Form2 frm2;
private void button1_Click(object sender, EventArgs e)
{
if (frm2 == null || frm2.IsDisposed)
{
frm2 = new Form2();
frm2.Show();
}
else
{
frm2.Activate();
frm2.WindowState = FormWindowState.Normal;
}
}