New to Telerik UI for WinForms? Download free 30-day trial

ControlXmlSerializer

The ControlXmlSerializer class allows you to serialize all properties of a given object. This class was created for easily saving and loading the layout of our controls (for example RadGridView and gauge controls). This article demonstrates how you can use this class to serialize your controls. In this particular example you will save the position of all nodes in RadPanorama along with other properties.

Save the layout.

private void SavePanoramaLayout(string fileName)
{
    ControlXmlSerializer ser = new ControlXmlSerializer();
    using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8))
    {
        writer.Formatting = Formatting.Indented;
        writer.WriteStartElement("RadPanorama");
        ser.WriteObjectElement(writer, this.radPanorama1);
    }
}

Load the layout.

public void LoadPanoramaLayout(string fileName)
{
    if (!File.Exists(fileName))
    {
        MessageBox.Show("File with layout not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }
    using (StreamReader sr = new StreamReader(fileName))
    {
        using (XmlTextReader textReader = new XmlTextReader(sr))
        {
            ControlXmlSerializer ser = new ControlXmlSerializer();
            textReader.Read();
            ser.ReadObjectElement(textReader, this.radPanorama1);
        }
    }
}
In this article