简体   繁体   中英

Best way to save the state of controls of Winform forms?

If your app has 1 form, that has n group boxes each of which contain any number of controls. How would you save the settings of all these controls?

A few things I am concerned are:

  1. I don't need properties like BackColor to be saved, because they aren't changed by the user.

  2. I need a way so that when I add new properties or remove some properties from these custom controls, they don't have problem loading the settings back.

How to best do this?

I was thinking of using serialization? If that would be better, which serialization is recommended? Binary/Xml/? Examples are welcome.

I would use data binding to bind the content of all relevant controls to a custom (non-ui) class, then I would just serialize (XML or binary) that class. I would choose XML serialization at least while you are developing, since it will help you when debugging (you can take a look at the serialized files at any time).

I would say if you are storing a model that the properties could change, you could take a look at Custom Serialization . It talks at the end of the article about storing versioning information for changes in the model to help with deserialization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM