我用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;
}
}
}