Stop user closing DocumnetWindows/ToolWindows

2 posts, 0 answers
  1. David
    David  avatar
    67 posts
    Member since:
    Aug 2010

    Posted 28 Feb 2012 Link to this post


    I'm creating an app that loads a number of forms and the raddock picks up as mdichildren

    I'm trying to get this so the user cannot close any of the forms that are loaded so context menus, ctrl+f4 and the x in top left is this possible?

    I have seen in an other forum post that you can do some of this using 

    DockWindow.AllowedDockState &= ~AllowedDockState.Hidden;

    if I use this it also stops me from closing the forms in code



  2. Stefan
    Stefan avatar
    2911 posts

    Posted 02 Mar 2012 Link to this post

    Hi David,

    Thank you for writing.

    To achieve the desired functionality, the following steps have to be considered.

    1. Remove the "Close" menu items from the context menu, as explained here:
    2. When adding a new HostWindow, remove the Close button: 
    void radDock1_DockWindowAdded(object sender, Telerik.WinControls.UI.Docking.DockWindowEventArgs e)
        //hide the close button
        ((HostWindow)e.DockWindow).DocumentButtons &= ~DocumentStripButtons.Close;
    3. Even that we have remove the context menu and the close button, the user still can close a window with Ctrl+F4, so in order to prevent the windows from closing we will use the DockWindowClosing event handler, where we will set the Cancel property to true.
    4. When you want to close a window, raise a flag, which will be taken into consideration in the DockWindowClosing event handler:
    private void radButton2_Click(object sender, EventArgs e)
        allowClosing = true;
        allowClosing = false;
    void radDock1_DockWindowClosing(object sender, Telerik.WinControls.UI.Docking.DockWindowCancelEventArgs e)
        if (!allowClosing)
            //cancel closing except in cases where we called it
            e.Cancel = true;

    Attached you can find a sample project, demonstrating this approach. 

    Let me know if I can be of further assistance.
    Kind regards,
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top