开发者

Serializing MDI Winforms for persistency

basically my project is an MDI Winform application where a 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 have done quite a bit of searching and found these:

How to auto save and auto load all properties in winforms C#?

Save WinForm or Controls to File

Basically from what I understand, the best approach is to serialize the data to XML, however winform controls are not serializable, so I would have 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 sort of a recursive a开发者_开发问答lgorithm to save all my controls, what is the best approach to do accomplish that? How would I then restore all the windows, should I use the memento design pattern for that? If I want to implement multiple users later, should I use Nhibernate to store all the object data in a database? I am still trying to wrap my head around the problem and if anyone has any experience or advice I would greatly appreciate it, thanks


You don't want to serialize the actual control instances. They should be created and destroyed along with the Form they reside in. Rather look at what you let the user customize. Layout and position? Very well, save out the Top and Left coordinates for each control along with a control identifier. Do you let the user add new controls? Save their ids along with a type identifier so when its time to reload you are able to recreate the controls at their previous position.

Whether you use XML or some other format, there is no best approach or best practice, choose what makes sense for your project. XML happens to be an easy to go with format with great support in the .Net Framework.


I know there is a software, LinsUI Layout Manager, which handle your problems very well. They have free version for interested developers. You can check the site. Cheer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜