)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to serialize and de-serialize properties of WinForms SplitContainerAdv?

Platform: WinForms |
Control: SplitContainerAdv |
Published Date: April 13, 2018 |
Last Revised Date: January 23, 2020 |
.NET Framework: 4

Serialization and Deserialization

This article describes, how to perform serialization and deserialization on the properties of SplitContainerAdv, since SplitContainer control doesn’t have built-in StatePersistence support. For instance, we have serialized and deserialized the values of SplitterDistance and BackgroundColor properties of SplitContainerAdv. The following code examples explains the same, 

Method to serializing the values of SplitContainerAdv:

public void LoadSplitContainer(string filename)
{
  string path = @"\" + filename;
  if (File.Exists(filename))
  {                
    FileStream stream = new FileStream((Environment.CurrentDirectory + path), FileMode.Open);
    XmlTextReader reader = new XmlTextReader(stream);
    XmlSerializer serializer = new XmlSerializer(typeof(List<SplitContainerAdvSettings>));
    List<SplitContainerAdvSettings> savedsettings = (List<SplitContainerAdvSettings>)serializer.Deserialize(reader);
    foreach (var settings in savedsettings)
    {
      this.splitContainerAdv1.SplitterDistance = settings.SplitterDistance;
      this.splitContainerAdv1.BackgroundColor = settings.SplitterBackColor;
    }
  }
}

Method to deserialize the values of SplitContainerAdv:

public void SaveSplitContainer(string filename)
{
  string path = @"\" + filename;
  List<SplitContainerAdvSettings> settingsList = new List<SplitContainerAdvSettings>();
  SplitContainerAdvSettings s_settings = new SplitContainerAdvSettings();
  s_settings.SplitterBackColor = this.splitContainerAdv1.BackgroundColor;
  s_settings.SplitterDistance = this.splitContainerAdv1.SplitterDistance;
  settingsList.Add(s_settings);
 
  using (XmlTextWriter writer = new XmlTextWriter(Environment.CurrentDirectory + path, Encoding.UTF8))
  {
    writer.Formatting = Formatting.Indented;
    XmlSerializer serializer = new XmlSerializer(typeof(List<SplitContainerAdvSettings>));
    serializer.Serialize(writer, settingsList);
  }
}

SplitContainerAdvSettings.cs:

[XmlRoot("Root")]
public class SplitContainerAdvSettings
{
  [XmlElement("Distance")]
  public int SplitterDistance
  {
    get;
    set;
  }
  [XmlElement("BackColor")]
  public BrushInfo SplitterBackColor
  {
    get;
    set;
  }
}

C#: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SplitContainer_StatePersistence_Sample766616685.zip

VB: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SplitContainer_StatePersistence_VB467219905.zip

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon