Category / Section
How to hide a floating window in MDI child from when minimizing it in WinForms Docking Manager?
2 mins read
Hide the floating window
Docking Manager does not have any special property for doing this, but forms SizeChanged event will provide the option to hide floating window when minimize the MDI child form. When the form size goes to minimized state, set the SetDockVisibility to false and call the SaveDockStateInfo method or else SetDockVisibility to true and call LoadDockStateInfo. Please refer the below code snippet which illustartes this:
C#
void Form1_SizeChanged(object sender, EventArgs e)
{
Console.WriteLine("Form1 size changed event triggered");
//Checks if the window state is minimized. If it is true,Dock visibility is false.
//otherwise visibility set to true.
if (this.WindowState == FormWindowState.Minimized)
{
this.SaveDockStateInfo();
this.dockingManager1.SetDockVisibility(this.panel1, false);
}
else
{
this.dockingManager1.SetDockVisibility(this.panel1, true);
this.LoadDockStateInfo();
}
}
VB
Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("Form1 size changed event triggered")
'Checks if the window state is minimized. If it is true,Dock visibility is false.
'otherwise visibility set to true.
If Me.WindowState = FormWindowState.Minimized Then
Me.SaveDockStateInfo()
Me.DockingManager1.SetDockVisibility(Me.Panel1, False)
Else
Me.DockingManager1.SetDockVisibility(Me.Panel1, True)
Me.LoadDockStateInfo()
End If
End Sub
The below code snippet is used, when there are multiple controls on the form:
C#
private void Form1_SizeChanged(object sender, System.EventArgs e)
{
Console.WriteLine("Form3 size changed event triggered");
//Collects the list of docked controls in the form.
IEnumerator ienum = this.dockingManager1.Controls;
ArrayList dockedctrls = new ArrayList();
while(ienum.MoveNext())
dockedctrls.Add(ienum.Current);
if(this.WindowState==FormWindowState.Minimized)
{
//Set the visibility to false for minimised state
this.SaveDockState();
foreach(Control ctrl in dockedctrls)
{
this.dockingManager1.SetDockVisibility(ctrl,false);
}
}
else
{
//Set the visibility to true for maximised and normal state
foreach(Control ctrl in dockedctrls)
{
this.dockingManager1.SetDockVisibility(ctrl,true);
}
this.LoadDockState();
}
}
VB
Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
Console.WriteLine("Form3 size changed event triggered")
'Collects the list of docked controls in the form.
Dim ienum As IEnumerator = Me.dockingManager1.Controls
Dim dockedctrls As ArrayList = New ArrayList()
Do While ienum.MoveNext()
dockedctrls.Add(ienum.Current)
Loop
If Me.WindowState=FormWindowState.Minimized Then
'Set the visibility to false for minimised state
Me.SaveDockState()
For Each ctrl As Control In dockedctrls
Me.dockingManager1.SetDockVisibility(ctrl,False)
Next ctrl
Else
'Set the visibility to true for maximised and normal state
For Each ctrl As Control In dockedctrls
Me.dockingManager1.SetDockVisibility(ctrl,True)
Next ctrl
Me.LoadDockState()
End If
End Sub
Sample: https://help.syncfusion.com/support/samples/KB/Tools.Windows/TDFormSize/FormSize.zip
Reference links: