【问题标题】:Error using Settings file.使用设置文件时出错。
【发布时间】:2014-08-12 20:17:12
【问题描述】:

我正在尝试使用 VS 2013 中的设置文件来存储 textBox1.Text 的文本,然后在您再次打开应用程序时重新输入。

我是这样设置的。

设置文件在这里:http://i.gyazo.com/e3aef293c3b8dbdfab269718de81a310.png

在公共 Form1() 上,我有这个来阅读文本。

    textBox1.Text = Properties.Settings.Default.aaa;

然后在保存它时,我拥有它。

    if (checkBox1.Checked)
    {
        Properties.Settings.Default.aaa = textBox1.Text;
    }

但我得到了错误

 'WindowsFormsApplication1.Properties.Settings' does not contain a definition for 'aaa' and no extension method 'aaa' accepting a first argument of type 'WindowsFormsApplication1.Properties.Settings' could be found (are you missing a using directive or an assembly reference?)

感谢您的帮助。

【问题讨论】:

  • 你有没有调试过以确保 textBox1 有文本?文本的阅读也有效吗?\
  • 两者都不起作用并且都给出相同的错误。
  • 你在哪里保存设置?? Properties.Settings.Default.Save();
  • 它在复选框代码中。我应该提到,这不会出错。
  • 检查生成的代码文件中的命名空间。我之前注意到这可能会失控。

标签: c# settings


【解决方案1】:

我遇到了同样的问题。我已将名称添加到设置文件中,但没有添加到 Visual Studio 项目中。我所要做的就是转到解决方案资源管理器,在属性下,双击 settings.settings(有一个轮子图标),它会自动生成丢失的代码。

【讨论】:

    【解决方案2】:

    我遇到了这个问题。问题是 Settings.settings 位于 Properties 文件夹和根文件夹中。我用另一个替换了属性文件夹中的一个。我认为如果您卸载并重新加载项目,可能会出现此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-02
      • 2013-05-06
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 2023-04-01
      相关资源
      最近更新 更多