windowsforms-2179-controls-and-libraries-form-layout-managers-layout-and-data-layout-controls-miscellaneous-save-and-restore-layout.md
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
}
Private Sub barButtonItem1_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
' Saves the layout to mylayout.xml.
layoutControl1.SaveLayoutToXml("mylayout.xml")
End Sub
Private Sub barButtonItem2_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
' 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.
Dim hiddenItemsCount As Integer = layoutControl1.HiddenItems.Count ' hiddenItemsCount = 1
End Sub
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.
See Also