Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在类型的对象上找不到C#属性_C#_Winforms_Visual Studio 2012 - Fatal编程技术网

在类型的对象上找不到C#属性

在类型的对象上找不到C#属性,c#,winforms,visual-studio-2012,C#,Winforms,Visual Studio 2012,错误: 未处理System.Configuration.SettingsPropertyNotFoundException 未找到设置属性自定义设置 编辑完全误解了要求。如果您试图在运行时创建此设置,请稍后再次阅读,以下是代码更改: //ensures no runtime errors if you try and view the setting before its created private bool _customSettingExists = false; public Form

错误:

未处理System.Configuration.SettingsPropertyNotFoundException 未找到设置属性自定义设置


编辑完全误解了要求。如果您试图在运行时创建此设置,请稍后再次阅读,以下是代码更改:

//ensures no runtime errors if you try and view the setting before its created
private bool _customSettingExists = false;
public Form1()
{
    InitializeComponent();
}

private void radButton1_Click(object sender, EventArgs e)
{
    //You're saving your CustomSetting to properties, so you should read it from Default.Properties
    if (_customSettingExists)
        radTextBox1.Text = Properties.Settings.Default.Properties["CustomSetting"].ToString();
}

private void radButton2_Click(object sender, EventArgs e)
{
    System.Configuration.SettingsProperty property = new
    System.Configuration.SettingsProperty("CustomSetting");
    property.SerializeAs = SettingsSerializeAs.Xml;
    property.DefaultValue = "Default";
    property.IsReadOnly = false;
    property.PropertyType = typeof(string);
    property.Provider =
    Properties.Settings.Default.Providers["LocalFileSettingsProvider"];

    property.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute());
    Properties.Settings.Default.Properties.Add(property);

    // Load settings now.

    Properties.Settings.Default.Reload();

    // Update the user itnerface.

    Properties.Settings.Default.Properties["CustomSetting"] = radTextBox1.Text;
    Properties.Settings.Default.Save();

    //now that you know a custom setting exists
    _customSettingExists = true;
}

错误发生在哪一行?radTextBox1.Text=(string)Properties.Settings.Default[“CustomSetting”];启动程序时会出现错误。当我尝试将文本加载到radTextBox1.text时,我认为您的应用程序无法读取设置文件。以下是一个可能的答案:。另外,检查它是否存在。帮帮我!不起作用,错误(文件user FFFFFFFF Your app.config的内容看起来正确。这是否反映在Addsettings项目中?如果转到项目属性并单击“设置”选项卡,是否所有设置都正确?app.config如何在用户创建自定义设置时进行设置,已在app.confi中创建。)您是否试图在运行时创建此自定义设置?但在编译时没有?
//ensures no runtime errors if you try and view the setting before its created
private bool _customSettingExists = false;
public Form1()
{
    InitializeComponent();
}

private void radButton1_Click(object sender, EventArgs e)
{
    //You're saving your CustomSetting to properties, so you should read it from Default.Properties
    if (_customSettingExists)
        radTextBox1.Text = Properties.Settings.Default.Properties["CustomSetting"].ToString();
}

private void radButton2_Click(object sender, EventArgs e)
{
    System.Configuration.SettingsProperty property = new
    System.Configuration.SettingsProperty("CustomSetting");
    property.SerializeAs = SettingsSerializeAs.Xml;
    property.DefaultValue = "Default";
    property.IsReadOnly = false;
    property.PropertyType = typeof(string);
    property.Provider =
    Properties.Settings.Default.Providers["LocalFileSettingsProvider"];

    property.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute());
    Properties.Settings.Default.Properties.Add(property);

    // Load settings now.

    Properties.Settings.Default.Reload();

    // Update the user itnerface.

    Properties.Settings.Default.Properties["CustomSetting"] = radTextBox1.Text;
    Properties.Settings.Default.Save();

    //now that you know a custom setting exists
    _customSettingExists = true;
}