Stop user closing DocumnetWindows/ToolWindows

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

    Posted 28 Feb 2012 Link to this post

    Hi,

    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

    RadDock1.CloseAllWindows();


    thanks 

    David
  2. Stefan
    Admin
    Stefan avatar
    2891 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: http://www.telerik.com/help/winforms/dock-architecture-and-features-using-the-contextmenuservice.html.
    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;
        radDock1.CloseAllWindows();
        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,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top