My program saves TextBoxes
via Properties.Settings so that I can close and open the program and it'll remember what's in it. 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. 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'
The Value
property expects a Decimal
value to be assigned to it but you were trying to assign string
. It should be
numericUpDown1.Value = Convert.ToDecimal(Settings.Default["H1"].ToString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.