简体   繁体   English

从Properties.Settings.Default加载NumericUpDown值?

[英]Loading a NumericUpDown value from Properties.Settings.Default?

My program saves TextBoxes via Properties.Settings so that I can close and open the program and it'll remember what's in it. 我的程序通过Properties.Settings保存TextBoxes ,这样我就可以关闭并打开程序了,它会记住它里面的内容。 That part works. 那部分有效。 However, the program also has some NumericUpDown boxes that I'd like the values to be saved as well, but the problem is that I can't seem to get it to load. 但是,该程序还有一些NumericUpDown框,我也希望保存这些值,但问题是我似乎无法加载它。 Here's my code: 这是我的代码:

Loading: 加载:

private void Form1_Load(object sender, EventArgs e)
{
   numericUpDown1.Value = Settings.Default["H1"].ToString();
}

Saving: 保存:

private void button4_Click(object sender, EventArgs e)
{
    Settings.Default["H1"] = numericUpDown1.Value;
    Settings.Default.Save();
}

The error is at 错误发生在

Settings.Default["H1"].ToString();  

and the message is 并且消息是

Error 1: Cannot implicitly convert type 'string' to 'decimal' 错误1:无法将类型'string'隐式转换为'decimal'

The Value property expects a Decimal value to be assigned to it but you were trying to assign string . Value属性需要为其分配Decimal值,但您尝试分配string It should be 它应该是

numericUpDown1.Value = Convert.ToDecimal(Settings.Default["H1"].ToString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM