Settings.Designer.cs
namespace WindowsApplication1.Properties
{
internal sealed partial class Settings :
global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)
(global::System.Configuration.ApplicationSettingsBase.Synchronized(
new Settings())));
public static Settings Default
{
get { return defaultInstance; }
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Form1")]
public string testSetting
{
get { return ((string)(this["testSetting"])); }
set { this["testSetting"] = value; }
}
}
}
{
internal sealed partial class Settings :
global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)
(global::System.Configuration.ApplicationSettingsBase.Synchronized(
new Settings())));
public static Settings Default
{
get { return defaultInstance; }
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Form1")]
public string testSetting
{
get { return ((string)(this["testSetting"])); }
set { this["testSetting"] = value; }
}
}
}
VS2005基本都完成了,现在我们读写时就只需要写几行代码就行了:
Properties.Settings config = Properties.Settings.Default;
//读取
string str = config.testSetting;
//写入
config.testSetting = "test value";
config.Save();
//读取
string str = config.testSetting;
//写入
config.testSetting = "test value";
config.Save();
其它更详细的写方法介绍:
http://www.codeproject.com/useritems/SystemConfiguration.asp
http://www.codeproject.com/useritems/SystemConfiguration.asp