日期:2014-05-18  浏览次数:20950 次

我用C#做winfrom怎么能让一个窗口只弹出一次呀?(希望能有代码)
我用C#做winfrom怎么能让一个窗口只弹出一次呀?(希望能有代码)

------解决方案--------------------
private static bool poped = false;
private void Form1_Load(object sender, EventArgs e)
{
try
{
if (Form1.poped)
{
throw new Exception("Form has poped,and it can only poped once!");
}
else
{
Form1.poped = true;
}
}
catch (Exception ex)
{
//your logic code
}
}
------解决方案--------------------
try


C# code
Form2 f2;
private void Button1_Click(object sender, EventArgs e)
{
    if (f2== null || f2.IsDisposed)
    {
        f2= new Form2();
        f2.Show();
    }
    else
    {
        f2.Activate();
    }
}