Description:
I'm using the SplitContainerControl component on a UserControl. The UserControl is dynamically loaded and disposed of. I want to save the SplitterPosition's value and restore it, so that an end-user's customization persists. Do you have a suggestion as to how to implement this feature?
Answer:
Custom data is easy to save by utilizing Serialization technology. You can implement a class with some fields and mark it with the Serializable attribute. After that, you can save and load these settings when necessary.
It may be difficult to determine exactly when to load settings. The SplitContainerControl must be created, docked and resized. If the SplitterPosition property is assigned before the control is resized, the actual value will be different when the control becomes visible, because the SplitterPosition is changed proportionally to the control's size. We advise that you try to use the Layout event of your UserControl to determine the moment when the settings can be loaded and assigned to the inner controls.
Please explore the corresponding example. Here are the step-by-step instructions:
- Launch the sample.
- Press the Load module button.
- Change the splitter position.
- Press the Unload module button.
- Press Load module - the splitter position is restored.
When the module is loaded or destroyed, the SplitterPosition value is logged in the Output window.
is there a sample for this ?
Hi,
We have the How the splitter's position can be saved on exit, and restored when the application is next launched example implementing this approach. You can also find it in the orange Examples section to the right of this ticket.