Skip to main content

Saving and Restoring a Bars Layout Automatically

  • 3 minutes to read

The bars’ layout contains settings for all bars and bar item links that determine their behavior, position, size, etc. Once saved, a layout can be applied to any BarManager. This allows you to customize a bar only once, and then apply the saved settings to other bars in different applications. This topic provides information on how to automatically save the layout of bars.

Please refer to the Saving and Restoring a Bars Layout Manually topic for information on how to save the layout manually. For information on saving/restoring the layout of dock panels, see Saving and Restoring the Layout of Dock Panels.

For information on saving the layout of bar commands within the Ribbon Quick Access Toolbar, see this link.

Note

When saving/loading the layout of bars and using the merging feature, take note of the following. If you saved the layout while bars have been merged, do not load this layout after the bars have been unmerged. Typically, you need to save and load the layout of bars while the bars are unmerged.

Saving and Restoring a Bars Layout Automatically

The Bar Manager can automatically save the bars’ layout to the system registry when the form that owns the bars is being closed, and restore it when the form loads. By default, this functionality is disabled. To activate it, you must specify the registry path where the information should be stored using the BarManager’s BarManager.RegistryPath property. Then, set the BarManager’s BarManager.AutoSaveInRegistry property to true so that the bars’ layout can be automatically saved/restored.

The following image shows how these properties can be specified at design time.

Layouts

The following sample code below demonstrates how this can be performed programmatically.

barManager1.RegistryPath = "DevExpress\\XtraBars\\Layouts\\MainLayout";
barManager1.AutoSaveInRegistry = true;

 

The bar items within the Bar Manager and within the stored layout are identified by the values of their BarItem.Id properties. For items created at design time, the BarItem.Id properties are initialized automatically. For items created via code, you need to initialize their BarItem.Id properties manually, to allow the layout of the bars to be correctly saved and restored. To set the BarItem.Id property’s value, the BarManager.GetNewItemId method can be used.

 

Note

The automatic saving/loading of the bars’ layout is only possible if the Bar Manager belongs to a Form class instance. Otherwise, you need to manually save/restore settings as described in the Saving and Restoring a Bars Layout Manually topic.

See Also