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.
Unfortunately, activation email could not send to your email. Please try again.

How do I prevent a single control from floating state?

 

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

 

Article ID: Published Date: Last Revised Date: Platform: Control:
1363 04/30/2011 07/10/2014 Windows Forms DockingManager
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.