在C#形式保存和恢复应用程序设置 [英] Saving and restoring app settings in C# Forms

查看:151
本文介绍了在C#形式保存和恢复应用程序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于C#应用程序对话框。我要保存首选项/设置的用户选择,这样我就可以在下次运行重新加载它们。

I have a C# Dialog based app. I want to save the preferences/settings the user choose, so that I could reload them in the next run.

我是新的C#,可能这是后话相当基本的,但我不知道。
我必须明确地写他们像INI或一个什么文件? ,或者是有一个内置的方式做到这一点。

I am new to C#, may be this is something quite basic but I do not know. Do I have to explicitly write them to a file like ini or something ? or is there a built in way to do that.

那种配置数据就像是复选框selelected,的NumericUpDown,的CheckedListBox - 检查的项目等。

The kind of config data is like checkboxes selelected, numericUpDOwn, checkedListbox - checked items etc

推荐答案

选择在设计控制。滚动一路攀升在属性窗口,然后展开(的applicationSettings)。点击显示按钮,打开一个对话框。选择其值应保持(如检查一个复选框)的财产,并在下拉菜单中单击新建

Select the control in the designer. Scroll all the way up in the Properties window and expand (ApplicationSettings). Click the indicated button to open a dialog. Select the property whose value should be persisted (like Checked for a check box) and click New in the dropdown.

小心一点,并不是所有的属性都适合于坚持这样。一个例子是表格的大小。你不想存储大小当窗体最小化或最大化,即大小不会恢复得不错。您需要通过添加在设置设计师设置一个只写它时,控制在合适的状态下做到这一点。在尺寸的情况下,这时候Resize事件运行和将WindowState是正常。

Be a bit careful, not all properties are suitable to be persisted like this. An example is the form's Size. You don't want to store the size when the form is minimized or maximized, that size won't restore well. You need to do this by adding the setting in the Settings designer an only write it when the control is in the right state. In the case of Size, that's when the Resize event runs and the WindowState is Normal.

这篇关于在C#形式保存和恢复应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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