应用程序设置,无需保存到 app.config

发布于 2024-12-14 06:01:19 字数 214 浏览 3 评论 0原文

Windows 窗体中的应用程序设置是存储应用程序范围属性的便捷方法。然而,在我当前的项目中,这些设置充斥着或多或少静态的颜色定义,导致 app.config 中出现噪音。有没有什么好方法可以防止设置被写入 app.config,仅依赖默认值?

我尝试将有问题的设置作为资源移出,但据我所知,Visual Studio 中的 Windows 窗体设计器没有提供将颜色资源值分配给控件上的属性的方法。

Application settings in Windows Forms is a convenient way to store application-wide properties. However, on my current project, these settings are littered with color definitions which are more or less static, causing noise in app.config. Are there any good way of preventing settings from being written to app.config, simply relying on the default value?

I tried moving the settings in question out as resources, but as far as I can tell, the Windows Forms designer in Visual studio provides no means of assigning color resource values to properties on controls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你不是我要的菜∠ 2024-12-21 06:01:19

应用程序设置是存放所有这些信息的正确位置。如果您担心噪音,请构建一个具有属性的类来保存您要保存的每个颜色属性。使用各种 [Serializing] 属性标记该类您可以将其放置在应用程序设置中,就像其他任何东西一样。现在,您的“嘈杂”颜色设置嵌套在层次结构中,不会混乱或淹没其他更重要的设置。

Application settings is the right place for all of this information. If you're worried about noise, build a class with properties to hold each of the color attributes you are saving. Mark the class up with the various [Serializable] attributes and you can place it in Application settings just like anything else. Now your "noisy" color settings are nested in the hierarchy and won't clutter up or drown out other, more significant, settings.

假装不在乎 2024-12-21 06:01:19

您可以使用设置,它已经准备好了特别是对于用户/机器特定配置。您可以存储简单的类型或更复杂的类型,但随后您必须(通常)将它们序列化为 XML 并存储为字符串。

You can use Settings, it's prepared especially for user/machine specific configuration. You can store there simple types or more complicated but then you'll have to (usually) serialize them to XML and store as string.

愛放△進行李 2024-12-21 06:01:19

您是否有权访问可以存储键值对的数据库?或者,或者如果它们是暂时的,那么您可以将它们存储在内存中的字典对象中。

存储在资源文件中听起来也是个好主意。您可以编写一个例程来迭代一组键值对。

Do you have access to a database you could store key value pairs in? Either that, or if they can be transient then you could store them in a dictionary object in memory.

Storing in a resource file sounds like a good idea too. You could just write a routine to iterate through a set of key value pairs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文