Search code examples
c#visual-studionumericupdownsettings.settings

Visual C# - Properties.Settings won't save correctly


I'm making a program that saves the Mouse X and Mouse Y coordinates from a NumericUpDown-Box into Settings.settings so the program launches with the last used values.

Both Input Boxes call the method "saveXY" when "ValueChanged" as seen here

My Problem is: the X coordinates get saved without problems, the Y coordinates don't get saved at all - but the code is the same:

    private void Form1_Load(object sender, EventArgs e)
    {
        movetoX.Value = Settings.Default.mouseX;
        movetoY.Value = Settings.Default.mouseY;
    }

-

    private void saveXY(object sender, EventArgs e)
    {
        Settings.Default.mouseX = (int)movetoX.Value;
        Settings.Default.mouseY = (int)movetoY.Value;
        Settings.Default.Save();
    }

Theese are my Settings.settings.

The .exe is availeble here.


Solution

  • thanks to hamix, its working now

    i deleted saveXY and wrote this:

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Settings.Default.mouseX = (int)movetoX.Value;
            Settings.Default.mouseY = (int)movetoY.Value;
            Settings.Default.Save();
        }
    

    it now saves X and Y