This is a migrated thread and some comments may be shown as answers.

Catching Child Form Closing.Cancel = true

4 Answers 228 Views
Dock
This is a migrated thread and some comments may be shown as answers.
MikeB
Top achievements
Rank 1
MikeB asked on 28 Jul 2009, 05:17 PM
Hi,

I'm using RadDock and I am trying to find a way within the RadDock.DockWindowClosing event handler to know if the form on the ActiveWindow has set Cancel = true in the Form.Closing handler.  I manually close the form in the DockWindowClosing handler like this:
  103             HostWindow window = dockMain.ActiveWindow as HostWindow;
  104             Form form = window.Content.FindForm();
  105             form.Close();

The form object is the correct form. There may be a reason why the form should not be closed and will set
the Cancel property to true; I can not find a way to detect this state. I really need to be able to cancel
a DockWindowClosing event based on the underlying form closing event.
How can I do this?

Thanks,
Mike



4 Answers, 1 is accepted

Sort by
0
MikeB
Top achievements
Rank 1
answered on 28 Jul 2009, 07:25 PM
Hi,

I found a way to do what I need to do.  If you have a more elegant solution, please let me know.

Thanks,
Mike

   93         private void dockMain_DockWindowClosing(object sender, Telerik.WinControls.UI.Docking.DockWindowCancelEventArgs e)
   94         {
   95             HostWindow window = e.DockWindow as HostWindow;
   96             Form form = window.Content.FindForm();
   97             form.Close();
   98             if( !form.IsDisposed)
   99                 e.Cancel = true;
  100         }
  101 
  102         private void dockMain_DockWindowAdded(object sender, DockWindowEventArgs e)
  103         {
  104             e.DockWindow.CloseAction = DockWindowCloseAction.CloseAndDispose;
  105         }
  106 
  107         private void frmMainRad_FormClosing(object sender, FormClosingEventArgs e)
  108         {
  109             while( dockMain.DockWindows.Count > 0)
  110             {
  111                 DockWindow dockWin = dockMain.DockWindows[dockMain.DockWindows.Count-1];
  112                 dockWin.Close();
  113                 if (!dockWin.IsDisposed)
  114                 {
  115                     e.Cancel = true;
  116                     return;
  117                 }
  118             }
  119         }
0
Georgi
Telerik team
answered on 31 Jul 2009, 04:33 PM
Hi Michael,

You can do this in a very simple way:

The Close method of the Form will generate the following events:

- Closing
- If accepted, Close
- Dispose

So, you may simply check for IsDisposed property after you call the Close method. If it is false, then the Form is prevented from closing. If it is true, then the Form is successfully closed.


Best wishes,
Georgi
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Garrison
Top achievements
Rank 1
answered on 26 Aug 2009, 12:32 PM
This doesnt seem to be the case if the form is an MDI child of a RadDock.
0
Georgi
Telerik team
answered on 27 Aug 2009, 01:26 PM
Hi Garrison,

Thank you for contacting us.

Could you please refer to this forum post, which is much similar and where I have answered you?


Greetings,
Georgi
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Dock
Asked by
MikeB
Top achievements
Rank 1
Answers by
MikeB
Top achievements
Rank 1
Georgi
Telerik team
Garrison
Top achievements
Rank 1
Share this question
or