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

Stop user closing DocumnetWindows/ToolWindows

1 Answer 300 Views
Dock
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 28 Feb 2012, 05:10 PM
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

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Mar 2012, 03:00 PM
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 >>
Tags
Dock
Asked by
David
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Share this question
or