Serializing MDI Winforms for Persistence
Basically my project is an MDI Winform application where the user can customize the interface by adding various controls and changing the layout. I would like to be able to save the state of the application for each user.
I searched quite a lot and found:
How to auto save and auto load all properties in winforms C #?
Save WinForm or controls to file
Mostly from what I understand, the best approach is to serialize the data to XML, however the winform controls are not serializable, so I would use surrogate classes:
http://www.codeproject.com/KB/dotnet/Surrogate_Serialization.aspx
Now do I need to write a surrogate class for each of my controls? I would need to write some kind of recursive algorithm to save all my controls, what is the best approach to do this? How can I then restore all windows, should I use the memento design pattern for this? If I want to implement multiple users later, should I use Nhibernate to store all object data in the database? I am still trying to wrap my head around the problem and if anyone has any experience or advice I would be very grateful for that, thanks
a source to share
You don't want to serialize the actual control instances. They must be created and destroyed along with the ones Form
in which they reside. Rather see what you allow the user to customize. Layout and position? Ok, store the Top and Left coordinates for each control along with the control ID. Do you allow the user to add new controls? Store their IDs along with the type ID, so when its time to reload, you can recreate the controls at their previous position.
If you are using XML or some other format, there is no best approach or best practice, choose what makes sense for your project. XML has proven to be easy to match with a highly supported format in the .NET Framework.
a source to share
I know there is LinsUI Layout Manager software out there that does a great job of handling your problems. They have a free version for interested developers. You can check the site . Cheer
a source to share