我需要序列化多个WinFrm状态的帮助 [英] I Need Help with Serializing Multiple WinFrm States

查看:60
本文介绍了我需要序列化多个WinFrm状态的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForm,它允许用户通过文本框为表单的当前配置分配名称.表单具有多个控件,即文本框,复选框等,它们代表与特定``名称''相关的表单的``状态''...

如果用户选择保存"表单,则我将序列化一个对象,该对象表示与名称"相关联的表单的状态".

我可以有多个序列化的表单对象...当用户加载表单时,这些序列化的对象将被加载到comboBox中.我需要在表单中填充
相应的状态"与从comboBox中选择的名称"相对应.

有人能指出我正确的方向吗?

预先感谢,

-DA

I have a WinForm that allows the user to assign a name to the current config of a form via a textBox. The form has multiple controls i.e. textBoxes, checkBoxes, etc that represent the ''state'' of the form associated with a specific ''name''...

If the user selects to ''save'' the form I serialize an object that represents the ''state'' of the form associated with the ''name''.

I can have multiple serialized form objects...when user loads the form these serialized objects are loaded into a comboBox. I need to populate my form with
the appropriate ''state'' the corresponds with the ''name'' that''s selected from the comboBox.

Can someone please point me in the right direction to accomplish this?

Thanks in advance,

-DA

推荐答案

最好的方法是执行以下操作:

1)为基础表单数据创建一个数据类.
2)在需要的地方将您的UI绑定到此类的属性.

The best way is to do the following :

1) Create a data class for the underlying form data.
2) Bind your UI to this class''s properties where needed.

public class dataobject
{
    public string CustomerName {get; set;} // -> txtCustomerName
    public List<string> City {get; set;} // -> CityComboBox
    // ...
}</string>



这样,您可以轻松地将数据对象序列化为XML,JSON等,并且只需将表单重新绑定到该对象即可从序列化的对象中恢复水分.



This way you can serialize the data object to XML,JSON, etc. easily and rehydrate from the serialized object by just rebinding your form to this object.


这篇关于我需要序列化多个WinFrm状态的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆