错误:
System.Configuration.SettingsPropertyNotFoundException未处理未找到设置属性CustomSetting 。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
namespace Addsettings
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void radButton1_Click(object sender, EventArgs e)
{
radTextBox1.Text = (string)Properties.Settings.Default["CustomSetting"];
}
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["CustomSetting"] = radTextBox1.Text;
Properties.Settings.Default.Save();
}
}
}