简体   繁体   English

如何将Settings.settings文件设置为类库,以便可以在每个应用程序中使用

[英]How to make Settings.settings file as a class library so that it can be used in every application

嗨,我是Windows应用程序中的应用程序设置的新手。我想在应用程序中使用设置处理程序,我必须将设置处理程序作为类库使用。如何执行此操作?

Why don't you use an xml file named like the one you suggested? 您为什么不使用一个像您建议的名称一样的xml文件? When starting application read data from that and change your app objects. 启动应用程序时,从中读取数据并更改您的应用程序对象。

The easiest way to create settings is to use the Visual Studio Settings Designer. 创建设置的最简单方法是使用Visual Studio设置设计器。 To get to the designer, open the project's Properties pages, and select the Settings tab: 要进入设计器,请打开项目的“属性”页面,然后选择“设置”选项卡:

We can see from the Settings grid, settings can have Application scope or User scope. 我们可以从“设置”网格中看到,设置可以具有“应用程序”范围或“用户”范围。 Application settings are those that apply across all users, and that do not change from run to run of the program. 应用程序设置是适用于所有用户的设置,并且在程序运行之间不会更改。 Once an Application setting is set in the designer, it can't be changed in code. 在设计器中设置了“应用程序”设置后,就无法在代码中对其进行更改。

User settings are those that change from user to user, and from run to run of an application. 用户设置是在用户之间以及应用程序的运行之间更改的设置。 They can be changed in code. 它们可以在代码中更改。 User settings are commonly used to store user preferences, such as window size and location. 用户设置通常用于存储用户首选项,例如窗口大小和位置。 Now fill out the Settings grid.The grid is self-explanatory.The default values are the values given in the Value column.Once you have entered the settings on the grid, save the project and close the Properties pages. 现在填写``设置''网格。网格是不言自明的。默认值是在``值''列中给出的值。在网格上输入设置后,保存项目并关闭``属性''页面。

The code to load the settings at runtime is very simple. 在运行时加载设置的代码非常简单。 The designer created a class for us that holds our settings. 设计师为我们创建了一个保存设置的类。 The class is located in a Properties namespace under our project name.Now we can add a using statement for the settings class in the UI code page.For further reference see the link below: 该类位于项目名称下的Properties命名空间中,现在我们可以在UI代码页面中为settings类添加using语句,有关更多参考,请参见下面的链接:

http://www.codeproject.com/Articles/15013/Windows-Forms-User-Settings-in-C http://www.codeproject.com/Articles/15013/Windows-Forms-User-Settings-in-C

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM