So schließen Sie die gesamte Anwendung, wenn die Anwendung mehr als zwei Formulare enthält, ohne dass das Meldungsfeld mehrmals angezeigt wird

Ich entwickle eine Anwendung mit Windows Forms. Das Projekt enthält drei Formulare: Ein Anmeldeformular ist das Hauptformular und zwei weitere untergeordnete Formulare für das Anmeldeformular.

Mein Problem ist, wenn Sie die gesamte Anwendung mithilfe von schließen möchtenApplication.Exit() Beim Schließen des Formulars wird in meiner Nachrichtenbox der Dialog mehrmals angezeigt.

1.Dieser Code im Anmeldeformular, dh im Hauptformular:

private void FrmLogIn_FormClosing(object sender, FormClosingEventArgs e)
    {
        DialogResult loginResult = MessageBox.Show("Do you want to close this application?","Close",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
        if (loginResult == DialogResult.Yes)
        {
            Application.Exit();
        }
    }

2.AdminForm-Abschlussereignis, das dem Anmeldeformular untergeordnet ist:

 private void FrmAdmin_FormClosing(object sender, FormClosingEventArgs e)
    {
        DialogResult loginResult = MessageBox.Show("Do you want to close this application?","Close",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
        if (loginResult == DialogResult.Yes)
        {
            Application.Exit();
        }
    }

3.Billoperations-Formular-Abschlussereignis, bei dem es sich um ein untergeordnetes Formular handelt, um sich anzumelden:

private void FrmBillOperation_FormClosing(object sender, FormClosingEventArgs e)
{
    DialogResult loginResult = MessageBox.Show("Do you want to close this application?","Close",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
    if (loginResult == DialogResult.Yes)
    {
        Application.Exit();
    }
}

Wenn ich in irgendeiner Form auf die Schaltfläche zum Schließen klicke, wird die MessageBox-Nachricht nur einmal angezeigt. Bitte hilf mir.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage