Closing Dialog Box without ending exe

At the moment I am trying to use a dialog box to put progress messages on the screen as a long process takes place beneath. The box has a close icon (that X at the top right of the title bar)  If the user clicks on the close icon this then closes the exe, but I would like to be able to keep the exe going and do some recovery routine to re-establish a known condition on the running exe.

Any ideas would be very welcome.

Thanks



Answer this question

Closing Dialog Box without ending exe

  • Jeff Lewis

    Yes, now that you have made me think about it it is defined as just a form which I pop with Form.Show() and close with Form.Close, so I should be able to get the normal close event shouldn't I!! I hadn't thought of it in that way. I'll give it a try tomorrow morning. Thanks
  • Tally622

    So exactly what kind of dialog box are we talking about here How did you define this object

  • noobProgrammer

    Hi Matthew

    Having successfully closed the dialog box, I need to be able to set a global variable when the close occurs, to warn the app that this has happened. Do you know how I can best capture the point that this close click happens (I assume that there is an event that I can subscribe to) so that I can set this variable please.

    Thanks


  • Guglielmo

    But it is really a dialog box, and that is the problem
  • Arvan

    Yes, that was the answer; it obviously gives everything time to respond rather than timing out and dying!  Thanks for the advice
  • martinhughes

    I'm just trying it now as we speak Give me a few mins
  • wardw

    Yes, you should be able to do exactly that. I believe that the event is refered (sp ) to as FormClosing. You should be able to set your variable there.

  • Kristin

    If you're closing an actual form and not really a dialog box (like a MessageBox), then you should be able to use the FormClosing event maybe...


  • feby

    Hi Matthew

    I added the two lines above the .Run line, and it now semi-works!! Depending on what the underlying program was doing when the dialog box x was clicked. I will have to do a bit more checking, but I though I would let you know the initial  results in the meantime.

    Could you explain a bit more about adding the extra code after the  .Run line please What code are you referring to


  • Knubbi

    It would appear that when the underlying program is in a holding loop, waiting for a third party action to complete, the exe bombs out when the X is clicked. I will try may putting an Application.DoEvents in the loop (unless you know something better )
  • HarisRashid

    In your "Program.cs" file, your Main() function should look something like this:


    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault( false );
        Application.Run( new Form1() );
    }

     

    Simply add the extra code after the line "Application.Run( new Form1() );"


  • Nathan Lewis

    I think that I must be getting too tired to think clearly. I put the code

    public void Progress_FormClosed(object sender, FormClosedEventArgs e)

    {

    Logging.WriteToLog(2, 2, "INFORMATION: Progress Closed");

    Globals.ProgressTerminated = true;

    }

    Into the Progress form class, but the application then terminated as soon as the progress form was opened, without tripping the debug set on the event! I'm off to bed to consider my options more tomorrow!


  • knallerthaar

    Well, I put the same code in this morning and it worked. Perhaps my PC is trying to tell me something about working late!!
  • Closing Dialog Box without ending exe