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 to prevent dragging of a particular panel in the form?

 

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

Article ID: Published Date: Last Revised Date: Platform: Control:
1262 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.