简体   繁体   English

如何在 c# 中添加 Properties.Settings.Default

[英]How to add Properties.Settings.Default in c#

I am not able to write "Properties.Settings.Default".我无法编写“Properties.Settings.Default”。 It is not coming in the dropdown list.它没有出现在下拉列表中。 Is there any namespace that we can add?我们可以添加任何命名空间吗?

Add your project namespace to the Properties namespace.将您的项目命名空间添加到 Properties 命名空间。 The default namespace defined in the project settings.项目设置中定义的默认命名空间。

For instance if your project default namespace is MyApp.例如,如果您的项目默认命名空间是 MyApp。

MyApp.Properties.Settings.Default

Make sure you are on the same namespace and try to access the properties like this :确保您在同一个命名空间中并尝试访问这样的属性:

namespace.Properties.Settings.Default

or if you are on different namespace don't forget to use或者如果你在不同的命名空间不要忘记使用

using namespace

An additional hint on top of the above answers:在上述答案之上的额外提示:

Go to solution explorer -> Properties folder -> Settings.settings -> Settings.Designer.cs file转到解决方案资源管理器 -> 属性文件夹 -> Settings.settings -> Settings.Designer.cs 文件

and see which namespace is being used there.并查看那里正在使用哪个命名空间。 Ensure that you are using this namespace in your code file as others have suggested确保您按照其他人的建议在代码文件中使用此命名空间

Once you setup your environment in the settings under properties of the app.在应用程序属性下的设置中设置环境后。 You want to reference it to the project like this:你想像这样将它引用到项目中:

using App.Properties.Settings使用 App.Properties.Settings

Then in the code you write you can use as example:然后在您编写的代码中,您可以使用以下示例:

userName.Settings.Default用户名.设置.默认

In this case userName is set within the settings.在这种情况下,用户名是在设置中设置的。

  1. Set your Setting in your project go to Project => property => go to setting在你的项目中设置你的设置去项目 => 属性 => 去设置

  2. Set your element (string,int, ecc...)设置您的元素(字符串、整数、ecc...)

  3. Save from program all values从程序中保存所有值

Properties.Settings.Default.User = txtUser.Text; Properties.Settings.Default.User = txtUser.Text; Properties.Settings.Default.Password = txtPass.Text; Properties.Settings.Default.Password = txtPass.Text; Properties.Settings.Default.Save(); Properties.Settings.Default.Save();

if you use Windows 10, this is the directory of setting Values: C:\\Users\\AppData\\Local<ProjectName.exe_Url_somedata>\\1.0.0.0<filename.config>如果您使用 Windows 10,这是设置值的目录:C:\\Users\\AppData\\Local<ProjectName.exe_Url_somedata>\\1.0.0.0<filename.config>

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

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