如何保存用户C#表单配置? [英] How to save user C# form configuration?

查看:87
本文介绍了如何保存用户C#表单配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有人对任何客户进行申请,

该客户想要关闭其应用程序,并在第二天打开它时
他找到了自己配置的所有表单配置.

我想对所有表单工具执行此操作,例如
图片框中的所有图像,所有radioButtons的状态等等,

assume some one do an application to any customer ,

this customer want to turn off his application and when he turn it on in the second day
he find all form configuration that he was configured .

i want to do this for all form tools ,for example
all images in picture boxes ,all radioButtons status and so on ,

推荐答案

我还可以提供一个选项来在不同运行之间保持应用程序状态.此选项是持久性实现的最简单术语.同时,它是最通用的,非侵入性的,并且易于维护,尤其是向后兼容.

您可以使用数据合同.请参阅 http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

这个想法是:创建一个应用程序状态的数据模型-仅包含状态,该状态应涵盖所有内容:所有窗口,已加载的文档,所有选择等.这应该只是一组数据类以及这些类的实例将形成一些完全描述状态的对象图.您将只需要两种方法:一种是根据实际应用程序状态填充数据,另一种是从数据填充UI以重现以前保存的状态.

其余的通过数据合同完成.要定义合同,您不应修改数据类中的任何内容.您只需要向合同的类型和成员添加一些属性.您甚至不需要更改访问修饰符即可将其设置为内部或公共-它们可以是私有的,但仍是合同的一部分.数据协定序列化程序可确保存储和正确加载整个对象图,就像之前保存的一样.

请参阅我过去的答案,在此我提倡这种全面且易于实施的方法:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [反序列化json字符串数组 [
I can offer one more option to persist your application state between different runs. This option is the easiest it term of persistence implementation; at the same time, it is the most universal, non-intrusive and good for maintenance, especially for backward compatibility.

You can use Data Contract. Please see http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

The idea is: you create a data model of your application state — only the state, which should cover everything: all windows, document loaded, all selections, etc. This should be just a set of data classes, and the instances of the classes will form some object graph totally describing the state. You will need just two methods: one to populate your data based on actual application state, another to populate UI from data to reproduce the state which have been saved before.

The rest is done via the data contract. To define the contract, you should not modify anything in your data classes; you just need to add some attributes to the types and members of the contract. You don''t even need to change access modifier to make them internal or public — they can be private and still be the part of the contract. Data contract serializers guarantee storing and exact loading of the whole object graph as it exactly was saved before.

Please see my past answers where I advocate this comprehensive and easy to implement approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

—SA


这并不困难.只是为您而浪费时间.

在VS中,打开您的项目,然后查看解决方案资源管理器.
在您的应用程序项目下,打开Properties 节点.
双击Settings.settings
添加一个具有合理名称的settings属性-例如,将其命名为imagePath.将其设置为String,并将其范围保留为User.
关闭设置,并在必要时保存.
在您的代码中,读取设置:
It''s not difficult. just time consuming for you.

In VS, open your project then look at the Solution Explorer.
Under your application project, open the Properties node.
Double click on Settings.settings
Add a settings property, with a sensible Name - call it imagePath for example. Set it to String, and leave its Scope as User.
Close the settings, and save if necessary.
In your code, to read the setting:
string imagePath = Properties.Settings.Default.imagePath;


并保存它们:


And to save them:

Properties.Settings.Default.imagePath = imagePath;
Properties.Settings.Default.Save();



对要在两次运行之间保留的所有对象重复以上操作.



Repeat for all the objects you want to persist between runs.


此处介绍了解决此类情况的更多选择:

http://msdn.microsoft.com/en-us/library/ms973902.aspx [ ^ ]
Few more options of solving these kind of scenarios are explained here:

http://msdn.microsoft.com/en-us/library/ms973902.aspx[^]


这篇关于如何保存用户C#表单配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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