Skip to main content

Save and Restore Form Layout

  • 3 minutes to read

A Layout Control’s layout contains settings that specify the behavior of its UI elements, their size, position, etc. You can save the layout to a stream, XML file or system registry. Once saved, the layout can then be applied to any Layout Control in any Windows Forms project.

Use the following methods to save and restore the layout:

Use the LayoutControl.OptionsSerialization property to access and customize the serialization settings.

The following example shows how to restore the layout that contains two panels from an XML file.

private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    // Saves the layout to mylayout.xml.
    layoutControl1.SaveLayoutToXml("mylayout.xml");
}
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    // Restores the layout from mylayout.xml.
    layoutControl1.RestoreLayoutFromXml("mylayout.xml");
    /* Once the layout is restored, the middle layout item is hidden.
    * The value of its 'Visibility' property was not changed.
    * This layout item was moved to the layout control's 'HiddenItems' collection.
    */
    int hiddenItemsCount = layoutControl1.HiddenItems.Count; // hiddenItemsCount = 1
}

Restore Form Layout - WinForms Layout Control

Tip

You can utilize the Persistence Behavior or Workspace Manager component to save and restore layouts for all supported DevExpress controls at once.

Use the LayoutControl.SetDefaultLayout method to temporarily save the layout to random-access memory (RAM). Use the Reset Layout menu command in the Layout Context Menu to restore the layout.

Note

For layout items created at runtime and UI controls they display, you need to initialize their Name property with unique value, to correctly save and restore the Layout Control’s layout.

Note

When creating localizable applications that support multiple cultures, you may encounter a situation of losing localized captions after restoring a layout from a data store. This happens if the current locale differs from the locale that had been applied when the layout was saved. To resolve the issue (to not restore item captions while restoring the layout), set the LayoutSerializationOptions.RestoreLayoutItemText option to false.

Concepts

Member Table

Task-Based Help

See Also