Urgent help

i have created a windows form as main form. I also created another form as close confirmation dialog.

So when i click on the close button which locates on the top right corner of my main form, it should display the close confirmation dialog. And there are two buttons on the confirmation dialog, "yes" and "no". Then click "yes", exit the whole application, or click"no", only close the confirmation dialog and focus back to the main form. However, when i click "no", it close (or may just hide) both of the forms, but not exit the whole application, which means the application is still running, but i couldn't see it. why's that I also created a menuitem called "exit", when click on the menuitem, it pops up the same confirmation dialog with those two buttons, and this time works fine.. i really do not understand why..

please give me any advices

thanks



Answer this question

Urgent help

  • Ready4u

    Thanks singhhome

    I have fixed up this problem

    cheers

    danny


  • slippyC

    I assume ur talking abt the close (X) button on the top of window.

    to avoid closing of main form, u should override OnClosing method in main Form and show ur confirmation dialog. if user selects NO, cancel close event.

    protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
    {
    ActionConfirmation frm = new ActionConfirmation();
    System.Windows.Forms.DialogResult rst = frm.ShowDialog();
    if (rst != System.Windows.Forms.DialogResult.Yes)
    {
    e.Cancel = true;
    return;
    }

    base.OnClosing(e);
    }

    U can also set ControlBox property of main form to false, if u want to avoid showing that close button on top. but still u should overrideOnClosing, to handle Alt + F4.



  • Urgent help