Articles in this section
Category / Section

How to prevent dragging of a particular panel in the form of WinForms Docking Manager?

2 mins read

Prevent dragging of a particular panel

To prevent dragging of a particular panel in the form the cancellable argument of the DragAllow event has to be set as True. Please refer the below code snippet which illustrates this:

C#

private void dockingManager1_DragAllow(object sender, Syncfusion.Windows.Forms.Tools.DragAllowEventArgs arg)
{
   //If the control being dragged is Panel1, then cancel the drag.
   if(arg.Control == this.panel1)
   {
      arg.Cancel = true;
      MessageBox.Show("Access denied to drag the window");
   }
   //If a tab group containing the panel is dragged then, cancel the drag.
   Syncfusion.Windows.Forms.Tools.DockHost dhost = arg.Control.Parent as  Syncfusion.Windows.Forms.Tools.DockHost;
   Syncfusion.Windows.Forms.Tools.DockHostController dhc = dhost.InternalController as Syncfusion.Windows.Forms.Tools.DockHostController;
   if(dhc.ParentController is Syncfusion.Windows.Forms.Tools.DockTabController)
  {
     Syncfusion.Windows.Forms.Tools.DockTabControl docktab = (dhc.ParentController as
Syncfusion.Windows.Forms.Tools.DockTabController).TabControl;
     foreach(DockTabPage tabpage in docktab.TabPages)
     {
         Control siblingcontrol = tabpage.dhcClient.HostControl.Controls[0];
         if(siblingcontrol == this.panel1)
         {
             if(dhost.RectangleToScreen(dhost.TitleBar.CaptionRect).Contains(Cursor.Position) == true)
             {
                 arg.Cancel = true;
             }
         }
     }
  }
}

 

VB

Private Sub dockingManager1_DragAllow(ByVal sender As Object, ByVal arg As Syncfusion.Windows.Forms.Tools.DragAllowEventArgs) Handles
dockingManager1.DragAllow
    'If the control being dragged is Panel1, then cancel the drag.
    If arg.Control Is Me.panel1 Then
       arg.Cancel = True
       MessageBox.Show("Access denied to drag the window")
    End If
    'If a tab group containing the panel is dragged then, cancel the drag.
    Dim dhost As Syncfusion.Windows.Forms.Tools.DockHost = CType(IIf(TypeOf arg.Control.Parent Is Syncfusion.Windows.Forms.Tools.DockHost,
arg.Control.Parent, Nothing), Syncfusion.Windows.Forms.Tools.DockHost)
    Dim dhc As Syncfusion.Windows.Forms.Tools.DockHostController = CType(IIf(TypeOf dhost.InternalController Is
Syncfusion.Windows.Forms.Tools.DockHostController, dhost.InternalController, Nothing), Syncfusion.Windows.Forms.Tools.DockHostController)
    If TypeOf dhc.ParentController Is Syncfusion.Windows.Forms.Tools.DockTabController Then
      Dim docktab As Syncfusion.Windows.Forms.Tools.DockTabControl = CType(IIf(TypeOf dhc.ParentController Is
Syncfusion.Windows.Forms.Tools.DockTabController, dhc.ParentController, Nothing),
Syncfusion.Windows.Forms.Tools.DockTabController).TabControl
      For Each tabpage As DockTabPage In docktab.TabPages
          Dim siblingcontrol As Control = tabpage.dhcClient.HostControl.Controls(0)
          If siblingcontrol Is Me.panel1 Then
             If dhost.RectangleToScreen(dhost.TitleBar.CaptionRect).Contains(Cursor.Position) = True Then
                 arg.Cancel = True
             End If
          End If
      Next tabpage
    End If
End Sub

 

Reference link: https://help.syncfusion.com/windowsforms/dockingmanager/docking-events#drag-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