在 .NET Winforms 应用程序中保存设置 [英] Save Settings in a .NET Winforms Application

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

问题描述

可能的重复:
最好的方法是什么存储 .NET 应用程序的用户设置?

关于如何从 Winforms 应用程序保存应用程序设置(每个用户),我发现了很多非常不同的示例.

I have found alot of VERY different examples as to how one would save application settings (per user) from a Winforms application.

我想在 c# 中正确的方法很简单,希望有人能启发我吗?

I imagine that the correct way to do this is very simple in c# and am hoping someone can enlighten me?

推荐答案

在某些时候,答案归结为品味问题.我想说你最终会得到至少这些选项:

At some point, the answer boils down to a matter of taste. I'd say you'll end up with at least these options:

  • 将其存储在注册表中,您在其中拥有 HKEY_CURRENT_USER 密钥.它下面的所有内容都是特定于用户的.当您想要存储一堆小的键值对时,这通常是首选.该系统的主要优点是您的设置很容易在几个不同的应用程序中找到和共享.要遵循此路径,您可以从此处开始.
  • 使用 .NET 应用程序设置,提供在运行时访问设置的最简单方法.同样,最好与小数据的键值对一起使用.IMO,这种方法的主要优点是它的简单性以及它使您能够将某些 .NET 类用作值(而不是强迫您将所有内容转换为更基本的类型)这一事实.要遵循此路径,您可以从此处开始.
  • 将其存储在用户数据文件夹中,这些文件夹通常隐藏在用户的配置文件目录下.当您想要存储大量数据或任意数量的文件时,这是首选.这种方法的主要优点是您可以像处理任何文件一样操作数据(这也可能是一个缺点).要遵循此路径,您可以从这里开始.
  • store it in the registry, where you have the HKEY_CURRENT_USER key. Everything under it is user-specific. This is usually preferred when you want to store a bunch of small key-value pairs. The main advantage of this system is that your settings are easy to find and share throughout several different applications. To follow this path, you can start from here.
  • using .NET Application settings, provides the easiest way to access your settings at runtime. Again, it's better for using with key-value pairs of small-sized data. IMO, the main advantages of this method is its simplicity and the fact that it empowers you to use some .NET classes as values (not forcing you to convert everything into more basic types). To follow this path, you can start from here.
  • store it in User Data folders, which are usually hidden under the user's profile directory. This is preferred when you want to store a large amount of data or any number of files. The main advantage of this method is that you can manipulate your data as you would with any files (that may also be a disadvantage). To follow this path, you can start from here.

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

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