how to use ApplicationSettingsBase

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I try to do something with ApplicationSettingsBase but after save I cannot
find a config file, and it does not load eather. Probably I forget somethign
but what ? Can someone check this ? I assume (according to the help) that
after clicking button2 I have a config file in application's folder, but I
have not.

Also I get an exception error if using [UserScopedSetting]. Wy ? There is
some explanation of this in the help, but (my poor) english does not
understeand it completely :(

namespace WindowsApplication1
{
partial class Form1: Form
{
MySettings cfg = new MySettings();

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(cfg.MyValue.ToString());
listBox1.Items.Add(cfg.MyFormColor.ToString());
cfg.MyValue = 567;
cfg.MyFormColor = System.Drawing.Color.Bisque;
}

private void button2_Click(object sender, EventArgs e)
{
cfg.Save();
}
}

public class MySettings: ApplicationSettingsBase
{
[ApplicationScopedSetting]
[DefaultSettingValue("123")]
public int MyValue
{
get { return (int)this["MyValue"]; }
set { this["MyValue"] = value; }
}

//[UserScopedSetting]
[ApplicationScopedSetting]
[DefaultSettingValue("Blue")]
public Color MyFormColor
{
get { return (Color)this["MyFormColor"]; }
set { this["MyFormColor"] = value; }
}
}
}
 
Back
Top