Skip to main content

How to: Save the layout between application runs

Changes in the layout that are made by end-users at runtime are not automatically saved between application runs. After the LayoutControl is destroyed, for instance, when a form is closed, all the end-user’s changes are lost. The solution that allows you to resolve this problem is to save the layout manually when the application closes and restore the saved layout when the application starts. This example demonstrates how to do this.

In this example, the layout will be stored in an XML file, so the LayoutControl.SaveLayoutToXml and LayoutControl.RestoreLayoutFromXml methods will be used. A list of all the methods for saving and loading the layout can be found in the Member Table: Save and Restore Layout topic.

string layoutFileName = "layout.xml";
//...
private void Form1_Load(object sender, EventArgs e) {
   if (System.IO.File.Exists(layoutFileName))
      layoutControl1.RestoreLayoutFromXml(layoutFileName);
}

private void Form1_Closing(object sender, FormClosingEventArgs e) {
   layoutControl1.SaveLayoutToXml(layoutFileName);
}