RadDock Advanced ToolWindow Layout

First of all, if you're coding for .NET and don't use a control suite (Telerik, DevExpress, etc), you're... missing out. The basic .NET controls are lacking. We code with Telerik, but they're all pretty good. 

Today's gem is the RadDock Control. The code below is fully functional, cut and paste and it will work. The RadDock supports 'ToolWindows' and 'DocumentWindows', This layout is done entirely with ToolWindows. 

 

Imports Telerik.WinControls.UI.Docking
Imports System.IO
Public Class ItemPriority2
 
    Private Sub ItemPriority2_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Dim strError As String = ""
        Try
            'save the layout when closing
            Dim strFileName As String
            strFileName = System.IO.Path.Combine(App.ApplicationDataDirectory, "ItemPriority.xml")
            Me.RadDock1.SaveToXml(strFileName)
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
    Private Sub ItemPriority2_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        Dim strError As String = ""
        Try
            'helps with memory bloat
            Dispose()
            GC.Collect()
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
 
    End Sub
 
    Private Sub ItemPriority2_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim strError As String = ""
        Try
            'load the save layout, if it exists
            Dim strFileName As String
            strFileName = System.IO.Path.Combine(App.ApplicationDataDirectory, "ItemPriority.xml")
 
 
            If File.Exists(strFileName) Then
                RadDock1.LoadFromXml(strFileName)
            Else
                'or, create a new layout
                InitializeToolWindows()
            End If
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
    Private Sub InitializeToolWindows()
        'there are 5 tool windows.
        'all are filled with a 'user control'. To create a user control, go to add > item > user control.
        'our user controls contain a single label to show that it is working, the production code will have grids
 
        'items
        'all 5 windows use the same code, only commented here.
 
        'load the user control
        Dim oItemPriorityItemsUC As New ItemPriorityItemsUC()
        'declare a ToolWindow
        Dim oToolWindowItems As New ToolWindow()
        'add the user control to the toolwindow
        oToolWindowItems.Controls.Add(oItemPriorityItemsUC)
        'populate some properties.
        'the Text is the window title
        oToolWindowItems.Text = "Items"
        'test Name is used in addressing the window
        oToolWindowItems.Name = "Items"
        'add the form to the RadDock
        Me.RadDock1.DockWindow(oToolWindowItems, DockPosition.Left)
 
        '=================================================================================================
        'tpo
        '=================================================================================================
        Dim oItemPriorityTPOUC As New ItemPriorityTPOUC()
        Dim oToolWindowTPO As New ToolWindow()
        oToolWindowTPO.Controls.Add(oItemPriorityTPOUC)
        oToolWindowTPO.Text = "TPOs"
        oToolWindowTPO.Name = "TPOs"
 
        'this time, we add it below the window above
        Me.RadDock1.DockWindow(oToolWindowTPO, oToolWindowItems, DockPosition.Bottom)
 
        '=================================================================================================
        'POs
        '=================================================================================================
        Dim oItemPriorityPOUC As New ItemPriorityPOUC()
        Dim oToolWindowPO As New ToolWindow()
        oToolWindowPO.Controls.Add(oItemPriorityPOUC)
        oToolWindowPO.Text = "POs"
        oToolWindowPO.Name = "POs"
 
        'note that this one is designated as 'tabbed'
        oToolWindowPO.DockState = DockState.TabbedDocument
 
        'same, below the window above
        'becase it is 'tabbed' and the dock position is 'fill', it will add as a tab to the window above
        Me.RadDock1.DockWindow(oToolWindowPO, oToolWindowTPO, DockPosition.Fill)
 
        '=================================================================================================
        'item qty
        '=================================================================================================
        Dim oItemPriorityItemQtyUC As New ItemPriorityItemQtyUC()
        Dim oToolWindowIQ As New ToolWindow()
        oToolWindowIQ.Controls.Add(oItemPriorityItemQtyUC)
        oToolWindowIQ.Text = "Item Quantities"
        oToolWindowIQ.Name = "Item Qty"
 
        'add below
        Me.RadDock1.DockWindow(oToolWindowIQ, oToolWindowPO, DockPosition.Bottom)
 
 
        '=================================================================================================
        'item priority
        '=================================================================================================
        Dim oItemPriorityUC As New ItemPriorityUC()
        Dim oToolWindowIP As New ToolWindow()
        oToolWindowIP.Controls.Add(oItemPriorityUC)
        oToolWindowIP.Text = "Suborders and Master Balance Remaining"
        oToolWindowIP.Name = "Item Priority"
 
        'add to the right
        Me.RadDock1.DockWindow(oToolWindowIP, DockPosition.Right)
 
        'without this line, we would have ToolWindows left and right, and a big space in the center
        Me.RadDock1.MainDocumentContainerVisible = False
 
        '=================================================================================================
        'sizing
        '=================================================================================================
        'optional
        oToolWindowTPO.TabStrip.SizeInfo.SizeMode = SplitPanelSizeMode.Relative
        oToolWindowTPO.TabStrip.SizeInfo.RelativeRatio = New System.Drawing.SizeF(0, 0.33F)
    End Sub
    Sub ShowWindow(strToolWindowName As String)
        Dim strError As String = ""
        Try
 
            'pop up a window
            Dim o As ToolWindow = RadDock1.DockWindows(strToolWindowName)
            o.DockState = DockState.Floating
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
    Private Sub btnItem_Click(sender As Object, e As EventArgs) Handles btnItem.Click
        Dim strError As String = ""
        Try
            'show the window
            ShowWindow("Items")
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
    End Sub
 
    Private Sub btnTPO_Click(sender As Object, e As EventArgs) Handles btnTPO.Click
        Dim strError As String = ""
        Try
            ShowWindow("TPOs")
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
 
    Private Sub btnItemQty_Click(sender As Object, e As EventArgs) Handles btnItemQty.Click
        Dim strError As String = ""
        Try
            ShowWindow("Item Qty")
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
 
    Private Sub btnPO_Click(sender As Object, e As EventArgs) Handles btnPO.Click
        Dim strError As String = ""
        Try
            ShowWindow("POs")
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
 
    Private Sub btnItemPriority_Click(sender As Object, e As EventArgs) Handles btnItemPriority.Click
        Dim strError As String = ""
        Try
            ShowWindow("Item Priority")
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
 
    Private Sub btnReload_Click(sender As Object, e As EventArgs) Handles btnReload.Click
        Dim strError As String = ""
        Try
            'force all the windows closed, then re-initialize
            RadDock1.DockWindows(4).Close()
            RadDock1.DockWindows(4).Dispose()
            RadDock1.DockWindows(3).Close()
            RadDock1.DockWindows(3).Dispose()
            RadDock1.DockWindows(2).Close()
            RadDock1.DockWindows(2).Dispose()
            RadDock1.DockWindows(1).Close()
            RadDock1.DockWindows(1).Dispose()
            RadDock1.DockWindows(0).Close()
            RadDock1.DockWindows(0).Dispose()
 
            InitializeToolWindows()
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
End Class

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences