Category / Section
How to prevent docking windows from being docked to certain sections of the host form in WinForms Docking Manager?
2 mins read
Docking events
The DockingManager has two very powerful events - DragAllow and DockAllow - that can be used separately or in tandem to tailor your application’s docking behavior. The DragAllow event is fired just before a drag operation commences while the DockAllow event is generated during the course of a drag operation when the dragged control is moved over a potential dock target. Both events allow for pre-emption and thus drag/dock operations may be deemed as allowed or otherwise based on the event arguments.
Two scenarios for the DockAllow event are shown below
C#
// DockingManager.DockAllow event handler in the Form hosting the DockingManager - Case 1 private void dockingManager1_DockAllow(object sender, Syncfusion.Windows.Forms.Tools.DockAllowEventArgs arg) { // Disallow all controls from being docked to the host Form’s left border if((arg.TargetControl == this) && (arg.DockStyle == Syncfusion.Windows.Forms.Tools.DockingStyle.Left)) arg.Cancel = true; } // DockingManager.DockAllow event handler - Case 2 private void dockingManager1_DockAllow(object sender, Syncfusion.Windows.Forms.Tools.DockAllowEventArgs arg) { //Disallow the dwNetwork docking window from being docked to the host Form’s left border if((arg.TargetControl == this) && (arg.DragControl == this.dwNetwork) && (arg.DockStyle == Syncfusion.Windows.Forms.Tools.DockingStyle.Left)) arg.Cancel = true; }
VB
' DockingManager.DockAllow event handler in the Form hosting the DockingManager - Case 1 Private Sub dockingManager1_DockAllow(ByVal sender As Object, ByVal arg As Syncfusion.Windows.Forms.Tools.DockAllowEventArgs) Handles dockingManager1.DockAllow If (arg.TargetControl Is Me) AndAlso (arg.DockStyle = Syncfusion.Windows.Forms.Tools.DockingStyle.Left ) Then arg.Cancel = True End If End Sub 'DockingManager.DockAllow event handler - Case 2 Private Sub dockingManager1_DockAllow(ByVal sender As Object, ByVal arg As Syncfusion.Windows.Forms.Tools.DockAllowEventArgs) Handles dockingManager1.DockAllow If (arg.TargetControl Is Me) AndAlso (arg.DragControl Is Me.panel1) AndAlso (arg.DockStyle = Syncfusion.Windows.Forms.Tools.DockingStyle.Left) Then arg.Cancel = True End If End Sub
Reference link: https://help.syncfusion.com/windowsforms/dockingmanager/docking-events