所以我有这个代码

public void Update_Click(object sender, EventArgs e)
{
    using (PccBiometricsHandler.Form1 ShowProgress = new PccBiometricsHandler.Form1())
    {
        menu.Items[2].Enabled = false;
        ShowProgress.ShowDialog();
        ShowProgress.FormClosed += new FormClosedEventHandler(MyForm_FormClosed);
    }
}

public void MyForm_FormClosed(object sender, FormClosedEventArgs e)
{
    updaterAccess();
    menu.Items[2].Enabled = true;
}


所以单击更新后,它将运行子窗体Form1
这是:

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    notifyIcon1.Visible = true;
    notifyIcon1.BalloonTipTitle = "Update Complete";
    notifyIcon1.BalloonTipText = "Successfully Update";
    notifyIcon1.ShowBalloonTip(500);
    timer1.Interval = 4000;
    timer1.Enabled = true;
    timer1.Tick += new EventHandler(timer1_Tick);
    timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    notifyIcon1.Dispose();
    this.Close();
}


如您所见,它在带有计时器的backgroundworker上运行以关闭子Form1

现在我的问题是关闭子Form1后,它没有运行MyForm_FormClosed,它应该再次启用menu.Items [2]和updaterAccess()

我想我的mainForm中缺少什么

最佳答案

在触发ShowDialog之前附加事件处理程序

public void Update_Click(object sender, EventArgs e)
    {
        using (PccBiometricsHandler.Form1 ShowProgress = new PccBiometricsHandler.Form1())
        {
            menu.Items[2].Enabled = false;
            ShowProgress.FormClosed += new FormClosedEventHandler(MyForm_FormClosed); //Attached the event handler before firing ShowDialog
            ShowProgress.ShowDialog();
        }
    }

10-08 13:33
查看更多