0

I have a question :

Does the Event "close childWindow" exists, when we click on the mark at the top right of childwindow?

Because I want to cancel all changes that can be done if I close the ChildWindow this way.

I can close the window with a button I create, but the user, still can close the ChildWindow the other way, so, none of the changed data are cancelled.

Thank you.

provençal le breton
  • 1,428
  • 4
  • 26
  • 43
  • 2
    Can you handle the closing event? See http://msdn.microsoft.com/en-us/library/system.windows.controls.childwindow.closing(v=vs.95).aspx - you should be able to conditionally set the Cancel property of the parameter CancelEventArgs to true to prevent the child window closing in your custom event handler. – Jay Feb 19 '13 at 09:39
  • Thanks, that is exactly what i was searching. – provençal le breton Feb 19 '13 at 09:52

1 Answers1

0

No sorry there is no such event as "Close ChildWindow" on windows standard Form. What you can do is create it yourself and everytime a new window opens you can throw this event from that new windows FormClosed event.

public event EventHandler CloseChildWindow;

And then when you open new windows.

Form1 frm = new Form1();
frm.FormClosed += (o, e) =>
     {
         if(CloseChildWindow!= null)
              CloseChildWindow(o, e);
     };
Evelie
  • 2,919
  • 2
  • 14
  • 21
  • 1
    ChildWindow is a silverlight class ( http://msdn.microsoft.com/en-us/library/dd538541(v=vs.95).aspx ) - not standard winforms. – Jay Feb 19 '13 at 09:40
  • Oh... Unfortunately I'm not very familiar with Silverlight, but wouldnt the "Closed" event be what you are looking for ? – Evelie Feb 19 '13 at 10:06
  • 1
    Not quite... in both cases (standard winforms forms and the silverlight class mentioned) I think you want 'Closing' rather than closed. 'Closing' is raised before 'Closed' and allows you to cancel (using the eventhandler argument) before the window gets closed. This is what the OP wanted to do. Closed just notifies you that a window is closed and you can't do anything about it at that point. – Jay Feb 19 '13 at 10:22
  • I think he want to cancle the current changes done in an editform when a childwindow is closed. Not cancle the closing itself? Upvoting you for awsomeness. – Evelie Feb 19 '13 at 10:47
  • @Evelie- Not according to the response to the original post where the OP said it was exactly what he was looking for. – Jay Feb 19 '13 at 10:49
  • No problems :) I learnt something about silverlight myself when I looked into it! – Jay Feb 19 '13 at 10:52