从form2结束事件启用SHOP按钮

时间:2018-01-06 09:42:25

标签: c#

我有一个问题,即当form2关闭时我无法启用商店按钮。

所以,我正在为我的点击游戏开店。当您按下SHOP按钮时,您应该禁用给定的form2(应该是商店,WIP)和商店按钮(按钮2),因为您可以在禁用时禁止商店按钮。关闭商店后,按钮应该再次启用,但我无法使其工作。

注意:商店的Form 2 Close按钮是sCloseBtn。

表格1代码:

 private void button1_Click(object sender, EventArgs e)
    {
        i += 1;
        if (i == 1)
        {
            label4.Text = "Cake";
        }
        else
        {
            label4.Text = "Cakes";
        }

        label3.Text = Convert.ToString(i);

    }

    public void button2_Click(object sender, EventArgs e)
    {
        WindowsFormsApplications2.Form2 secondForm;
        secondForm = new WindowsFormsApplications2.Form2();

        if (isInGui == false) {
            secondForm.Show();
            button2.Enabled = false;
            isInGui = true;
        }
        else if (isInGui == true)
        {
            button2.Enabled = true;
            isInGui = false;
        }
       }

表格2代码:

 private void sCloseBtn_Click(object sender, EventArgs e)
    {
        Close();
    }

    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {

    }

感谢所有帮助:)

1 个答案:

答案 0 :(得分:0)

解决这个问题的一种方法是移动事件处理程序" Form2_FormClosing"到Form1,

public partial class Form1 : Form
{
    // ...whatever is in your form already...

    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
        button2.Enabled = true;
        isInGui = false;
    }

    // ...
}

并在创建后将其分配给secondForm的事件,即。

secondForm = new WindowsFormsApplications2.Form2();
secondForm.FormClosing += Form2_FormClosing;