Articles in this section
Category / Section

How to prevent a single control from floating state in WinForms Docking Manager?

5 mins read

Docking events

Currently we have a property called DisallowFloating which prevents from floating for all docked controls. There is no method to prevent from floating for a single docked control.

Usually the end user will float a Docked Control by using the DockContextMenu or by dragging that control.So to prevent a control from floating , the best solution is to remove the MenuItem for floating from the DockContextMenu and redock the control to previous dock position if it loses docking.This can be accomplished by the following code in the event handlers for DockContextMenu and DockStateChanged

C#

//This code Will prevent a Panel from floating
private void dockingManager1_DockContextMenu(object sender, Syncfusion.Windows.Forms.Tools.DockContextMenuEventArgs arg)
{
   //removes the menu item
   if(arg.Owner == panel1)
     arg.ContextMenu.ParentBarItem.Items.Remove(arg.ContextMenu.ParentBarItem.Items[1]);
}
private void dockingManager1_DockStateChanged(object sender, Syncfusion.Windows.Forms.Tools.DockStateChangeEventArgs arg)
{
   DockHost dhost = panel1.Parent as DockHost;
   DockHostController dhc = dhost.InternalController as DockHostController;
   DockInfo di = dhc.DICurrent;
   //checking if the control is in floating
   if(di.dStyle==DockingStyle.Fill && panel1.Parent.Parent !=null )
   {
       Point p= dhost.PointToScreen(dhost.TitleBar.CaptionRect.Location );
       if(panel1.Parent.Parent is FloatingForm)
       {
           FloatingForm ff=panel1.Parent.Parent as FloatingForm ;
           //Performing a double click operation to restore the previous state
           ff.HandleDoubleClick(p);
       }
   }
}

 

VB

' This code Will prevent a Panel from floating
Private Sub dockingManager1_DockContextMenu(ByVal sender As Object, ByVal arg As Syncfusion.Windows.Forms.Tools.DockContextMenuEventArgs) Handles dockingManager1.DockContextMenu
   'removes the menu item
   If arg.Owner Is panel1 Then
      arg.ContextMenu.ParentBarItem.Items.Remove(arg.ContextMenu.ParentBarItem.Items(1))
  End If
End Sub
Private Sub dockingManager1_DockStateChanged(ByVal sender As Object, ByVal arg As Syncfusion.Windows.Forms.Tools.DockStateChangeEventArgs) Handles dockingManager1.DockStateChanged
   Dim dhost As DockHost = CType(panel1.Parent, DockHost)
   Dim dhc As DockHostController = CType(dhost.InternalController, DockHostController)
   Dim di As DockInfo = dhc.DICurrent
   'checking if the control is in floating
   If di.dStyle = DockingStyle.Fill And Not TypeOf panel1.Parent.Parent Is DBNull Then
      Dim p As Point = dhost.PointToScreen(dhost.TitleBar.CaptionRect.Location)
      If TypeOf panel1.Parent.Parent Is FloatingForm Then
          Dim ff As FloatingForm = CType(panel1.Parent.Parent, FloatingForm)
          'Performing a double click operation to restore the previous state
          ff.HandleDoubleClick(p)
      End If
   End If
End Sub

 

 UG document link: https://help.syncfusion.com/windowsforms/dockingmanager/docking-events

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied