Catching Child Form Closing.Cancel = true

5 posts, 0 answers
  1. MikeB
    MikeB avatar
    42 posts
    Member since:
    May 2008

    Posted 28 Jul 2009 Link to this post

    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



  2. MikeB
    MikeB avatar
    42 posts
    Member since:
    May 2008

    Posted 28 Jul 2009 Link to this post

    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         }
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Georgi
    Admin
    Georgi avatar
    296 posts

    Posted 31 Jul 2009 Link to this post

    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.
  5. Garrison
    Garrison avatar
    10 posts
    Member since:
    Apr 2008

    Posted 26 Aug 2009 Link to this post

    This doesnt seem to be the case if the form is an MDI child of a RadDock.
  6. Georgi
    Admin
    Georgi avatar
    296 posts

    Posted 27 Aug 2009 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready