We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to restrict close option of specific MDIChild in DockingManager?

Platform: WinForms |
Control: DockingManager |
Published Date: September 20, 2018 |
Last Revised Date: May 23, 2019 |
.NET Framework: 4

In DockingManager, it is possible to restrict the close option of specific MDIChild by handling DockVisibilityChanging and DockVisibilityChanged event.

 

For Example,

 

Here we have restricted the close option for Output window. The following code demonstrates the same.

 

C#

/// <summary>
/// Here we have specified Output window as it cannot be closed. But, when closing Main Form all ChildMDIForm needs to be closed. So, it is handled with the help of this flag property.
/// </summary>
 
bool canCloseOutputMDI;
 
/// <summary>
/// Occurs when MDIChildForm is closed.
/// </summary>
 
public event EventHandler MDIChildFormClosed;
 
//For MDIChildForm closing
 
this.MDIChildFormClosed += ChildFormClosed;
 
//Raising when Changing the state of DockVisibility
 
this.dockingManager1.DockVisibilityChanging += DockingManager1_DockVisibilityChanging1;
 
//Raising after changed the state of DockVisibility changed
 
this.dockingManager1.DockVisibilityChanged += DockingManager1_DockVisibilityChanged;
 
/// <summary>
/// Occurs when Form is loaded
/// </summary>
private void Form1_Load(object sender, EventArgs e)
{
this.dockingManager1.LockDockPanelsUpdate();
this.dockingManager1.SetAsMDIChild(this.Solution, true);
this.dockingManager1.SetAsMDIChild(this.ToolBox, true);
this.dockingManager1.SetAsMDIChild(this.Property, true);
this.dockingManager1.SetAsMDIChild(this.Output, true);
this.dockingManager1.UnlockDockPanelsUpdate();
}
 
 
/// <summary>
/// Invoked when DockVisibility is Changed
/// </summary>
 
private void DockingManager1_DockVisibilityChanged(object sender, DockVisibilityChangedEventArgs arg)
{
this.RaiseMDIChildFormClosed(arg.Control);
}
 
/// <summary>
/// Invoked when DockVisibility is Changing
/// </summary>
 
private void DockingManager1_DockVisibilityChanging1(object sender, DockVisibilityChangingEventArgs arg)
{
//Restrict close option for Output MDIChild window
if (!canCloseOutputMDI && this.dockingManager1.IsMDIMode(arg.Control) && this.dockingManager1.GetDockLabel(arg.Control) == "Output")
arg.Cancel = true;
canCloseOutputMDI = false;
}
 
/// <summary>
/// Invoked when before Form is closing
/// </summary>
/// <param name="e"></param>
 
protected override void OnFormClosing(FormClosingEventArgs e)
{
foreach (var item in this.dockingManager1.ControlsArray)
{
canCloseOutputMDI = true;
if (this.dockingManager1.GetDockVisibility(item))
this.dockingManager1.SetDockVisibility(item, false);
}
e.Cancel = false;
base.OnFormClosing(e);
}
 
/// <summary>
/// This will MDIChildFormClosed event
/// </summary>
public void RaiseMDIChildFormClosed(Control control)
{
if (this.MDIChildFormClosed != null)
{      
this.MDIChildFormClosed(control, new EventArgs());
}
}
 
/// <summary>
/// This event will be triggered when MDIChild in DockingManager is closed
/// </summary>
private void ChildFormClosed(object sender, EventArgs e)
{
if (sender is Control)
{
MessageBox.Show((sender as Control).Name + " : Form Closed");
}
}

 

Screenshot

 

Showing closed window

Figure 1: Property Window can be closed.

 

Showing not closing window

Figure 2: Output window cannot be closed.

 

Sample:

 

C#: DockingManagerSample

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile