在 .NET Winforms 应用程序中保存设置
我发现了很多非常不同的示例,说明如何从 Winforms 应用程序保存应用程序设置(每个用户)。
我想在 C# 中执行此操作的正确方法非常简单,希望有人能启发我?
Possible Duplicate:
What is the best way to store user settings for a .NET application?
I have found alot of VERY different examples as to how one would save application settings (per user) from a Winforms application.
I imagine that the correct way to do this is very simple in c# and am hoping someone can enlighten me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用.NET 提供的设置基础结构。在项目的属性页面中,转到“设置”页面,然后定义您的设置。您可以将每个设置的范围定义为“应用程序”或“用户”。将自动生成一个类来从代码访问这些设置。
要访问设置 Foo 和 Bar,请使用:
You can use the settings infrastructure provided by .NET. In your project's property pages, go to the Settings page, and define your settings. You can define the scope of each setting as "Application" or "User". A class will be automatically generated to access these settings from code.
To access settings Foo and Bar, use :
我会使用应用程序设置。它非常简单,并且会为您解决一些问题(例如,在没有管理访问权限的情况下,没有对可能安装应用程序的文件夹的写入权限,这排除了直接使用 app.config 进行设置的情况)。
I would use Application Settings. It's pretty straightforward and will take care of some issues for you (such as not having write access to the folder where your app may be installed without administrative access, which rules out directly using app.config for your settings).
在某些时候,答案归结为品味问题。我想说您最终至少会得到以下选项:
At some point, the answer boils down to a matter of taste. I'd say you'll end up with at least these options: