TelerikDeveloper.com

TelerikDeveloper.com

sgray128 8/24/2015 6:50:44 PM

RadSplitContainer - Save and Load info

This article will show how to save the panel sizes for a RadSplitConainer to storage and read them back in again



Imports System.Drawing
Imports System.Windows.Forms
Imports Telerik.WinControls.UI
Imports System.Collections.Specialized
 
Public Class DispatchQueue
 
 
    Protected Sub save()
        Try
            'in this example, we know that the form holds one RadSplitContainer with two panels
 
            'declare a StringCollection to hold the Panel info
            Dim oPanelInfo As New StringCollection
 
            'loop through the panels, add the height:width info to the collection.
            For Each panel As SplitPanel In RadSplitContainer1.SplitPanels
                Dim size As String = String.Format("{0}:{1}", panel.Size.Width, panel.Size.Height)
                oPanelInfo.Add(size)
            Next
 
            'data access code to save the panel info to the User Setting table
            Dim oFPUserSetting As New DynData.FPUserSetting("Geometry", String.Format("{0}_RadSplitContainer", Me.Name), App.UserName, App.Database)
            If Not oFPUserSetting.isPopulated Then
                oFPUserSetting.UserName = App.UserName
                oFPUserSetting.SettingType = "Geometry"
                oFPUserSetting.SettingName = String.Format("{0}_RadSplitContainer", Me.Name)
            End If
 
            'concatenate the two panel's info together
            oFPUserSetting.SettingValue = String.Format("{0}|{1}", oPanelInfo(0), oPanelInfo(1))
            oFPUserSetting.save(App.Database)
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, True)
        End Try
    End Sub
 
    Protected Sub Restore()
        Try
            'restore the setting of the RadSplitContainer.
            'in this form, the container has two panels
 
            'query the database and get the settings that we want to restore
            Dim oFPUserSetting As New DynData.FPUserSetting("Geometry", String.Format("{0}_RadSplitContainer", Me.Name), App.UserName, App.Database)
            'if we didn't find any settings, keep on going
            If oFPUserSetting.isPopulated Then
                RadSplitContainer1.SuspendLayout()
 
                'Read the settings into an array. We have two panels, so this array will have two entries
                Dim oPanelInfo As String() = oFPUserSetting.SettingValue.Split("|")
                Dim index As Integer = 0
                For Each c As String In oPanelInfo
                    RadSplitContainer1.SplitPanels(index).SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Absolute
                    RadSplitContainer1.SplitPanels(index).SizeInfo.AbsoluteSize = Parse(c)
                    index += 1
                Next
                RadSplitContainer1.ResumeLayout(True)
            End If
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, True)
        End Try
    End Sub
 
    Private Function Parse(size As String) As Size
 
        Dim sizeParts As String() = size.Split(":"c)
        Dim height As Integer = Integer.Parse(sizeParts(0))
        Dim width As Integer = Integer.Parse(sizeParts(1))
        Return New Size(height, width)
    End Function
 
    Private Sub DispatchQueue_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        save()
    End Sub
 
    Private Sub DispatchQueue_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Try
            FPCommon.App.ReadConfigFile("Dispatch", "dd.Config")
 
            Restore()
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, True)
        End Try
 
    End Sub
End Class