private void button2_Click(object sender, EventArgs e)
{
frmBook f = new frmBook();
if (frmBook.formCount<1)
{ richTextBox1.Text = "前四名成绩为" + "\n" + label7.Text + label2.Text + "\n" + label8.Text + label4.Text + "\n" + label9.Text + label5.Text + "\n" + label10.Text + label6.Text;
this.T1 = this.richTextBox1.Text;
f.TextBox2Text = T1;
f.Show();
}
else
{
MessageBox.Show("已经打开一个记事本!");
}
}
这个是frmBook这个窗体的弹出,但是我写的判断不管用。
public partial class frmBook : Form
{
public static int formCount = 0;
public frmBook()
{
InitializeComponent();
formCount++;
}
public string TextBox2Text
{
set { this.rtxtBook.Text = value; }
get { return this.rtxtBook.Text; }
} private void frmBook_FormClosed(object sender, FormClosedEventArgs e)
{
formCount--;
}真的不知道哪里出错了。。
这句执行完了 frmBook.formCount的值已经是1了
if (frmBook.formCount<1)对吗
改成这样试试
if (frmBook.formCount<1){
frmBook f = new frmBook();
}
{
if (frmBook.formCount<1)
{
frmBook f = new frmBook();
richTextBox1.Text = "前四名成绩为" + "\n" + label7.Text + label2.Text + "\n" + label8.Text + label4.Text + "\n" + label9.Text + label5.Text + "\n" + label10.Text + label6.Text;
this.T1 = this.richTextBox1.Text;
f.TextBox2Text = T1;
f.Show();
//p = false;
}
else
{
MessageBox.Show("已经打开一个记事本!");
}