Saving and Restoring the Layout of Dock Panels
- 4 minutes to read
DevExpress controls allow you to save their layout information to data stores (an XML file, a stream, or the system registry) and restore the layout later. Refer to the following help topic to learn more: Save and Restore Layouts of DevExpress controls.
The layout of dock panels defines how panels are arranged within a form, as well as their positions, sizes, and visibilities. This layout can be saved to the system registry, an XML file, or a stream.
Note
Instead of saving only the docking layout, you can also use the Workspace Manager component to save and load the layout of your entire application in a centralized way. Refer to this link for details.
Saving the Layout of Dock Panels
To save the layout of dock panels, use the following methods: DockManager.SaveLayoutToRegistry, DockManager.SaveLayoutToStream, and DockManager.SaveLayoutToXml. The saved layout can then be restored with the DockManager.RestoreLayoutFromRegistry, DockManager.RestoreLayoutFromStream, and DockManager.RestoreLayoutFromXml methods respectively.
The DockManager.SaveLayoutToRegistry method takes the path parameter, which specifies the registry key where settings are saved. You are allowed to define whole and partial registry keys. For instance, if you define a partial key (“Software\MyCompany\MyTool"), the full path will be as follows: “HKEY_CURRENT_USER\Software\MyCompany\MyTool". If you wish to store a layout in another root key, you should define the entire path, for instance: “HKEY_LOCAL_MACHINE\Software\MyCompany\MyTool".
Example 1
In the following example, the layout of dock windows is saved to an XML file.
string xmlFile = "c:\\XtraBars\\DockStates\\MainState.xml";
dockManager1.SaveLayoutToXml(xmlFile);
// ...
dockManager1.RestoreLayoutFromXml(xmlFile);
Note
A DockManager can be used together with the DocumentManager component, which manages the display of documents/windows. DockManager.SaveLayoutTo...
methods allow you to save the layout of dock panels only. To save the layout of documents/windows, use the SaveLayoutTo...
methods of the DocumentManager.View object (see BaseView.SaveLayoutToRegistry, BaseView.SaveLayoutToXml, and BaseView.SaveLayoutToStream).
Important
It is necessary to restore the DockManager’s layout before restoring the layout of the DocumentManager.
You can handle the DockManager.RestoreLayoutError / BaseView.RestoreLayoutError event to fix exceptions that occur during the restore layout operation.
Saving the Layout of Dock Panels and Bars
When a BarManager resides within the form, the layout of the dock panels can be saved simultaneously with the layout of the bars to the same destination. For this purpose, the dock manager should be assigned to the BarManager.DockManager property. The layouts of dock panels and bars can then be saved automatically or manually.
To save the layouts manually, call the BarManager’s required method (BarManager.SaveToRegistry, BarManager.SaveLayoutToStream, or BarManager.SaveLayoutToXml). The layouts can then be restored with the BarManager’s corresponding method. See the Saving and Restoring a Bars Layout Manually document for more information.
The layouts of dock panels and bars can be saved automatically by the Bar Manager to the system registry. The layouts are automatically saved when the form is closed and then restored when the form is opened again. To enable the automatic saving feature, set the BarManager.AutoSaveInRegistry property to true and then specify the registry path from the BarManager.RegistryPath property. For more information, refer to the following help topic: Saving and Restoring a Bars Layout Automatically.
Note: When adding a dock manager at design time to a form that already contains a BarManager, the BarManager.DockManager is initialized automatically. This property is also initialized when adding a Bar Manager at design time to a form that already has a dock manager. If you create a dock manager and/or a Bar Manager in code, the BarManager.DockManager property must be initialized manually.
Example 2
The following example shows how to manually save the layouts of bars and dock windows to the system registry.
barManager1.DockManager = dockManager1;
barManager1.RegistryPath = "XtraBars\\Layouts\\MainLayout";
barManager1.SaveLayoutToRegistry();
// ...
barManager1.RestoreLayoutFromRegistry();