c#正确表格关闭检查并重新打开

时间:2014-07-13 04:55:10

标签: c# wpf forms

我对C#WPF有点新意。在下面的代码中,如何正确检查表单关闭/最小化后,可以重用表单对象。我想要做的是当窗体关闭时使用相同的对象打开它?有点奇怪的是,将它设为null并声明对象也不起作用?

private static SumByJournal sbj = null;    

public static void ShowSumByJournal()
    {
        if (sbj == null)
        {
            MessageBox.Show("null object");
            sbj = new SumByJournal();
            sbj.Activate();
            sbj.ShowDialog();
        }
        else
        {
            if (sbj.IsActive == true)
            {
                MessageBox.Show("active bro");
            }
            else
            {
                sbj.Activate();
                if (sbj.IsActive == true)
                {
                    MessageBox.Show("active test");
                }
                else
                {
                    MessageBox.Show("still not active");
                }
            }
            if (sbj.IsVisible == true)
            {
                MessageBox.Show("visible bro");
            }
            else
            {
                sbj.ShowDialog();
                sbj.Show();
                if (sbj.IsVisible == true)
                {
                    MessageBox.Show("visible test");
                }
                else
                {
                    MessageBox.Show("no visisable also.");
                }

            }
            if (sbj.IsInitialized == true)
            {
                MessageBox.Show("initlize");
            }

            sbj.ShowDialog();

            // so force it to null;
            sbj = null;
            sbj = new SumByJournal();
            sbj.Activate();
            sbj.ShowDialog();
            // still does not show ?? 
        }

    }

0 个答案:

没有答案
相关问题