3 回答
TA贡献1772条经验 获得超5个赞
你都看到了,这里你调用的是Properties["UID"].DefaultValue,也就是设置了属性的默认值!
这样是不对的,请直接赋值,如Properties["UID"]= txtUID.Text;
你可以看看系统帮你生成的那个属性的代码是怎么赋值的,肯定是这样的:
[UserScopedSettingAttribute()]
public String UID
{
get { return (String)this["UID"]; }
set { this["UID"] = value; }
}
TA贡献1815条经验 获得超13个赞
DefaultValue和Value不一样,可以在Setting.Designer.cs里看到自动生成的代码是:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("9")]
public int UID {
get {
return ((int)(this["UID"]));
}
set {
this["UID"] = value;
}
}
Value设置的是属性值,DefaultValue设置的是那个DefaultSettingValueAttribute的值,这个是在Reload()是读取的,一般的时候读取的时候是Value,当然设置属性值之后都需要Save(),保存当前属性值。
TA贡献1796条经验 获得超4个赞
Properties.Settings.Default.UID=TextBox1.Text;//这句赋值
Properties.Settings.Default.Save();//这句保存
Properties.Settings.Default.Properties["UID"].DefaultValue = txtUID.Text;
这个没保存吧。
数据存放在;项目目录下:Properties/Settings.Settings文件里
- 3 回答
- 0 关注
- 332 浏览
添加回答
举报
