0

I'm trying to access settings from a settings file(MySettings) that I have created through the SharpDevelop Template:

Setting:

[global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("")]
        public string s_Username {
            get {
                return ((string)(this["s_Username"]));
            }
            set {
                this["s_Username"] = value;
            }
        }
    }

Code:

void MainFormLoad(object sender, EventArgs e)
    {

        MessageBox.Show(AdhesionCharting.Properties.MySettings.s_Username);

    }

Error:

'AdhesionCharting.Properties.MySettings' is a 'type', which is not valid in the given context

John Meyer
  • 37
  • 1
  • 8

1 Answers1

0

If you look at your MySettings.cs file you will see that the class is not static. There is a Default property which is static that can be used. So your code should be changed to be:

void MainFormLoad(object sender, EventArgs e)
{
    MessageBox.Show(AdhesionCharting.Properties.MySettings.Default.s_Username);
}
Matt Ward
  • 47,057
  • 5
  • 93
  • 94