How to Persist Layout Between Application Runs
- 3 minutes to read
The ExpressLayout Control allows you to persist a layout to an INI file, registry, or stream. This topic describes how you can accomplish this automatically between application runs, and how to use a set of specially designed methods to do this manually at arbitrary points in an application.
Layout information stored within external data stores contains the following group and item attributes:
Group attributes:
Name.
Caption and its horizontal alignment.
Parent group‘s name.
Layout direction of items within a group.
Flag indicating whether a group is expanded.
Flag indicating whether a group displays a border.
Flag indicating whether a group is an auxiliary hidden group.
Item attributes:
Name.
Caption and its alignment options.
Parent group‘s name.
Position within its parent group.
Except for the Name and Hidden properties, the list includes all the settings that can be customized by end-users. These settings are sufficient to restore the layout at any time, provided that the layout control contains the same items and groups as when it was stored. Changes to item or group properties other than those listed above should be persisted manually.
Persisting Layout Information Automatically
The layout control allows you to automatically preserve its data between application runs in an INI file or the system registry. By default, this functionality is disabled. To activate it, you need to specify the destination storage device and location for the information being stored:
- An INI file. Set the layout control’s OptionsStoring.StoreToIniFile property to True and designate the filename using the OptionsStoring.IniFileName property. You can specify the full path to the file in order to store this file to a specific location, other than the application’s starting folder. You can also use paths relative to the application’s starting folder.
- The system registry. Set the layout control’s OptionsStoring.StoreToRegistry property to True and designate the registry path via the OptionsStoring.RegistryPath property. Values of this property represent the registry keys relative to the HKEY_USERS root key.
Once these properties are set, the layout information is automatically saved when the layout control is destroyed, and is loaded when the control is created.
Persisting Layout Information Manually
You can save the layout information to an INI file, registry, custom storage or stream at any time by calling a corresponding method:
An INI file. Call the layout control’s SaveToIniFile (Container.StoreToIniFile) method or set the OptionsStoring.StoreToIniFile and OptionsStoring.IniFileName properties as shown above, and call the Store method.
The system registry. Call the layout control’s SaveToRegistry (Container.StoreToRegistry) method or set the OptionsStoring.StoreToRegistry and OptionsStoring.RegistryPath properties as shown above, and call the Store method.
Custom storage. Call the layout control’s Container.StoreToStorage method.
A stream. Call the layout control’s SaveToStream (Container.StoreToStream) method.
To restore the layout, call the layout control’s LoadFromIniFile, Container.RestoreFromStorage, LoadFromRegistry (Container.RestoreFromRegistry), LoadFromStream (Container.RestoreFromStream), or Restore method.
End-users can store and restore layout information by clicking the corresponding buttons within the Customization Form.
The following code sample demonstrates how to save the layout information to a specific file and then restore from it.
var
AFileName: string;
begin
AFileName := 'layout.ini';
dxLayoutControl1.SaveToIniFile(AFileName);
...
dxLayoutControl1.LoadFromIniFile(AFileName);
end;