)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to hide a floating window in MDI child from when minimizing it in WinForms Docking Manager?

Platform: WinForms |
Control: DockingManager |
Published Date: April 30, 2011 |
Last Revised Date: December 6, 2019

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: http://help.syncfusion.com/support/samples/KB/Tools.Windows/TDFormSize/FormSize.zip

Reference links:

  1. https://help.syncfusion.com/windowsforms/dockingmanager/dock-window#showhide-dock-windows
  2. https://help.syncfusion.com/windowsforms/dockingmanager/serialization#persisting-dock-state-in-default-storage

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
Live Chat Icon