tags:

views:

112

answers:

2

I want to execute some code inside 'Form1' but after the dialog is closed and it's not visible. I know that I can do this outside the dialog after calling ShowDialog() but I don't like it.

I tried in 'FormClosed' but it seems that the dialog it's still visible when this event is fired. Also if I call 'Hide()' the main dialog it's minimized - something interesting happens

+3  A: 

I would create a static method on the dialog, and in this method show the dialog, and execute whatever needs executing after it closes, e.g.

public static void ShowAndDoStuff()
{
  MyDialog dialog = new MyDialog();
  dialog.ShowDialog();
  dialog.DoStuff();
}
Grzenio
+1  A: 

You can try Closing Event, also the hide method is a good idea. I suggest a mix solution just use a boolean variable (ie: sysclose ) with false default value, in the closing event if sysclose is false then cancel the close and hide the form then do your job set the sysclose to true and call this.close

Ahmed Said