求助,关于验证窗体已经打开的方法
触发新窗体创建后,当再次按下创建按钮后想弹出个消息告诉用户窗体已经创建,该怎么做呢?请教各位高人!!感谢
我用tag实现的,不知道有没有更好的方法。
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace test
{
public partial class Form1 : Form
{
Form newForm;
public Form1()
{
InitializeComponent();
newForm = new Form();
newForm.Tag = false;
newForm.FormClosed += new System.Windows.Forms.FormClosedEventHandler(newForm_FormClosed);
}
private void ThreadProc()
{
newForm.Tag = true;
newForm.ShowDialog();
}
private void button1_Click(object sender, EventArgs e)
{
if (false == (bool)newForm.Tag)
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
else
{
MessageBox.Show("Already created");
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void newForm_FormClosed(object sender, FormClosedEventArgs e)
{
newForm.Tag = false;
}
}
}