Articles in this section
Category / Section

How to persist dock state in a database of WinForms Docking Manager?

1 min read

Serialize dock state

To persist docking information into a data base. It is necessary to serialize the state information into a stream. After that, the stream is written into the database. Please refer to the below code snippet which illustrates this.

C#

private void button1_Click(object sender, EventArgs e)
{
   // Saving dockstate to memory stream
   MemoryStream ms = new MemoryStream();
   AppStateSerializer aser = new AppStateSerializer(SerializeMode.BinaryFmtStream, ms);
   this.dockingManager1.SaveDockState(aser);
   aser.PersistNow();
   //Code to store the memory stream into database.Depends upon the database
   MessageBox.Show("Saved in DB");
}
private void button2_Click(object sender, EventArgs e)
{
   //Code to retrieve data(stream) from database. Depends upon the database
   //Retrive dockState from DB
   String val = "";
   byte[] bytes = System.Text.Encoding.ASCII.GetBytes(val);
   MemoryStream ms = new MemoryStream(bytes);
   ms.Position = 0;
   AppStateSerializer aser = new AppStateSerializer(SerializeMode.BinaryFmtStream, ms);
   this.dockingManager1.LoadDockState(aser);
   MessageBox.Show("Loaded from DB");
}

 

VB

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   'Saving dockstate to memory stream
   Dim ms As MemoryStream = New MemoryStream()
   Dim aser As AppStateSerializer = New AppStateSerializer(SerializeMode.BinaryFmtStream, ms)
   Me.DockingManager1.SaveDockState(aser)
   aser.PersistNow()
   'Code to store the memory stream into database.Depends upon the database
   MessageBox.Show("Saved in DB")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
   'Code to retrieve data(stream) from database.Depends upon the database
   'Retrive dockState from DB
   Dim val As String = ""
   Dim bytes As Byte() = System.Text.Encoding.ASCII.GetBytes(val)
   Dim ms As MemoryStream = New MemoryStream(bytes)
   ms.Position = 0
   Dim aser As AppStateSerializer = New AppStateSerializer(SerializeMode.BinaryFmtStream, ms)
   Me.DockingManager1.LoadDockState(aser)
   MessageBox.Show("Loaded from DB")
End Sub

 

Sample: https://help.syncfusion.com/support/samples/KB/Tools.Windows/TDDBper/DBper.zip

UG document link: https://help.syncfusion.com/windowsforms/dockingmanager/serialization

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