0

退出按钮单击事件。

`void buttn2_Click(object sender, EventArgs e) //QUIT BUTTON CLICK EVENT. 
    {
       if (MessageBox.Show("LEAVE CURRENT GAME?", "QUIT CONFIRMATION", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            this.Controls.Remove(buttn); .. PLAY AGAIN BUTTON.
            this.Controls.Remove(buttn2);
            for (int i = 0; i <= gencount; i++)
            {
               this.Controls.Remove(panel[i]);
               this.Controls.Remove(label200[i]);
               this.Controls.Remove(label100[i]);
               this.Controls.Remove(Tbox[i]);
            }
               this.Controls.Remove(AttemptsRem);
               this.Controls.Remove(AttemptNum);
               this.Controls.Remove(TimeRem);
               this.Controls.Remove(Min);
               this.Controls.Remove(Sec);
               this.Controls.Remove(misc);
               this.ReftoForm2.Show(); To go back to the starting form 
        }
        else
            buttn.Focus();
    }

Form1 激活事件。

 private void Form1_Activated(object sender, EventArgs e)
    {
        if (ui_formCowsAndBulls.rdbSinglePlayer.Checked == true)//Static variable
        {

            //GetAllTheWords(); .. Am still working on getting a the 4 letter words
            //GetDistinctElements(); .. randomly out of a list.
            textBox1.PasswordChar = '*';
            textBox1.Focus();
            foreach (string val in distinctWords)
            {
                if (val == "ABLE") .. For single player,the guess word is ABLE.
                    textBox1.Text = val;
            }
        }
        else
        {
            textBox1.Text = string.Empty;
            textBox1.Enabled = true;
            textBox1.Focus();
        }
        //textBox1.Focus();
    }

再次播放点击事件

 private void buttn_Click(object sender, EventArgs e) //PLAY AGAIN CLICK EVENT.
    {
        for (int i = 0; i <= gencount; i++)
          {
            this.Controls.Remove(panel[i]);
            this.Controls.Remove(label200[i]);
            this.Controls.Remove(label100[i]);
            this.Controls.Remove(Tbox[i]);
          }

            this.Controls.Remove(AttemptsRem);
            this.Controls.Remove(AttemptNum);
            textBox1.Text = string.Empty;
            textBox1.Enabled = true;
            textBox1.Focus();
            incrpanel = 0; gencount = 0; count = 10;
            this.Controls.Remove(TimeRem);
            this.Controls.Remove(Min);
            this.Controls.Remove(Sec);
            this.Controls.Remove(misc);
            this.textBox1.PasswordChar = '*';
            this.Controls.Remove(buttn);
            this.Controls.Remove(buttn2);
    }

我的问题是当我点击消息框按钮NO时我没有从消息框出来。我第一次玩游戏时从消息框出来,但是如果我第二次玩游戏,我需要点击两次才能从消息框出来。如果我第三次玩游戏,我需要单击是或否按钮 3 次才能从消息框出来。我希望你们能帮助我。我发布了同样的问题之前但没有代码。希望代码有所帮助。

4

1 回答 1

1

我认为您可能正在订阅Click-event:

button1.Click += new EventHandler(buttn2_Click);

在代码中多次调用它的位置,因此当单击按钮时,将显示 MessageBox,并且当buttn2_Click事件处理程序(您发布的代码)完成时,它将再次运行,显示另一个 MessageBox,订阅(上面的“...+=...”)完成的次数。

于 2012-11-18T10:00:33.800 回答