tags:

views:

340

answers:

2

Windows Forms application:

  • MainForm.cs - Windows Form
  • Settings.settings - Settings class with an entry named "Test"
  • Auxiliary.cs

I can access the "Test" setting in my Settings.settings class within my MainForm.cs file just fine:

Settings.Default.Test = "Hello World!";
Settings.Default.Save();
String test = Settings.Default.Test;

But I can't seem to figure out how to access my "Test" setting in the Auxiliary.cs file.

Any advice?

A: 

Visual Studio places the Settings in the ApplicationName.Properties namespace by default.

So try by prepending Settings with the namespacename like this:

String test = ApplicationName.Properties.Settings.Default.Test;

Or place a using statement at the top of your auxiliary.cs file like this:

using ApplicationName.Properties;

...

String test = Settings.Default.Test;
fretje
+3  A: 

Import the namespace for your project settings into the Auxiliary.cs class.

So let's say your application is called TestForm1, the wizard will automatically create a namespace 'TestForm1'. The Settings class will be generated by the wizard in the namespace 'TestForm1.Properties'.

using TestForm1.Properties;

//... namespace/class stuff here

Settings.Default.Test = "Hello World!";
Settings.Default.Save();
String test = Settings.Default.Test;
meklarian