如何组织保存具有子表单的多个表单的表单设置
为了保存表单属性,我可能会使用某种 xml 序列化程序。但我有几种带有子表单的表单。因此,可以有两到三种不同类型的(主)表单,其中两者都可以有多种类型的子表单。除主窗体外,所有窗体都是动态添加的。
那么我该如何最好地处理此设置的保存/加载呢?每个表单都应该有自己的设置文件吗?谁负责保存/加载每个表格?希望有一些提示和技巧。
For saving form properties I will likely use some sort of xml serializer. But I have several forms with child forms. So there can be two-three different type of (main) forms, where both can have several types of child forms. The forms are all added dynamically, except for the main form.
So how would I best handle save/load of settings for this? Should each form have it's own setting file? And who shall be responsible for saving/loading each form? Would appreciate some tips and tricks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很久以前我也遇到过类似的问题。我们使用
XmlSerializer
来实现这一点。基本思想是,我们创建了一个具有一系列形式的类。每次创建新表单时,我们都会将其添加到数组中(关闭表单时将其删除)。保存和加载非常容易。在应用程序启动时,我们加载了反序列化的 xml 文件。在
Application.Run(form)
之后,我们将放置保存方法。也许这不是最佳实践,但效果很好。
I had a similar problem long time ago. We're using the
XmlSerializer
to accomplish that. The basic idea was, that we'd created a a class, that has an array of forms. Every time a new form was created, we'd added it to the array (removed it when form was closed).The saving and loading was easy enough. At application start, we'd loaded the deserialized the xml file. And right after
Application.Run(form)
we'd put the save methods.Maybe this is not best practice, but it just worked well.