Results 1 to 3 of 3

Thread: Creating user settings on the fly and issue with debugging an app using user settings

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2004
    Location
    Kansas, USA
    Posts
    351

    Creating user settings on the fly and issue with debugging an app using user settings

    I need to be able to store user settings so that they can be retrieved the next time the app is run. Basically the settings I need to save are various paths for file opening and saving. Part of my issue is when I use Settings.Default.Properties.Add it seems to be adding user settings but they not show up next time I debug.

    I also want to create a new setting "on the fly" as needed since I don't want to add these settings in the settings table in "Properties -> Settings" and recompile.

    My code looks like this:

    Code:
       public class Config
        {
            public SettingsProperty GetSetting(string name)
            {
                var enumerator = Settings.Default.Properties.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    SettingsProperty setting = (SettingsProperty)enumerator.Current;
                    if (setting.Name == name)
                    {
                        return setting;
                    }
                }
                return null;
            }
    
            public void SetSetting(SettingsProperty property)
            {
                var enumerator = Settings.Default.Properties.GetEnumerator();
                bool found = false;
                while (enumerator.MoveNext())
                {
                    SettingsProperty setting = (SettingsProperty)enumerator.Current;
                    if (setting.Name == property.Name)
                    {
                        setting = property;
                        Settings.Default.Save();
                        found = true;
                    }
                }
                if (!found)
                {
                    Settings.Default.Properties.Add(property);
                    Settings.Default.Save();
                }
            }
        }
    If I create a new setting using that code It seems to save OK. I can see the new setting in properties in debug but they disappear when I close the app. What am I doing wrong?
    Thanks,
    Eric
    --------------------------------------------------------------------------------------------------------------------
    VB.net/C# ... Visual Studio 2019
    "None of us are as smart as all of us."

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,170

    Re: Creating user settings on the fly and issue with debugging an app using user sett

    What you're asking for is not supported. I haven't read everything, let alone tested it, but you might find something useful here:

    https://stackoverflow.com/questions/...gs-at-run-time

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2004
    Location
    Kansas, USA
    Posts
    351

    Re: Creating user settings on the fly and issue with debugging an app using user sett

    Thanks @jmcihinney. That make sense as to why creating new settings on the fly didn't work.
    Thanks,
    Eric
    --------------------------------------------------------------------------------------------------------------------
    VB.net/C# ... Visual Studio 2019
    "None of us are as smart as all of us."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width