How to tear-off DockContainerItem using code
Categories: Docking Toolbars and Menus, DotNetBar for Windows Forms
Tearing off the DockContainerItem from the Bar control involves following steps:
- Remove DockContainerItem from its current Bar
- Create new Bar to host the DockContainerItem
- Add DockContainerItem to the newly created Bar control
- Add Bar control to the DotNetBarManager
- Float or Dock the Bar
// Remove DockContainerItem from its current parent Bar previousParent = dockContainerItem1.ContainerControl as Bar; previousParent.Items.Remove(dockContainerItem1); // Create new Bar to hold the DockContainerItem that is torn off Bar bar = new Bar(dockContainerItem1.Text); bar.LayoutType = eLayoutType.DockContainer; bar.GrabHandleStyle = eGrabHandleStyle.Caption; bar.Stretch = true; bar.Name = "float" + dockContainerItem1.Name; // Add it to DotNetBarManager dotNetBarManager1.Bars.Add(bar); // Add DockContainerItem to the newly created bar bar.Items.Add(dockContainerItem1); // Specify inital floating location bar.InitalFloatLocation = new Point(100, 100); // If not already set, specify default floating size dockContainerItem1.DefaultFloatingSize = new Size(200, 300); // Float the bar bar.DockSide = eDockSide.None;
' Remove DockContainerItem from its current parent previousParent.Items.Remove(DockContainerItem1) ' Create new Bar to hold the DockContainerItem that is torn off Dim bar As Bar = New Bar(DockContainerItem1.Text) bar.LayoutType = eLayoutType.DockContainer bar.GrabHandleStyle = eGrabHandleStyle.Caption bar.Stretch = True bar.Name = "float" + DockContainerItem1.Name ' Add it to DotNetBarManager DotNetBarManager1.Bars.Add(bar) ' Add DockContainerItem to the newly created bar bar.Items.Add(DockContainerItem1) ' Specify inital floating location bar.InitalFloatLocation = New Point(100, 100) ' If not already set, specify default floating size DockContainerItem1.DefaultFloatingSize = New Size(200, 300) ' Float the bar bar.DockSide = eDockSide.None
The following samples can be downloaded to show this in action.
DockContainerItemTearOffCS
DockContainerItemTearOffVB
Related posts:
Leave a Reply!