   Application Settings in C Sharp
  I have set up a form that has 2 options in it. 1) mtpServer2) SmtpPortHow can I read them in and change them and then save them back to the Application Settings file. PLEASE make it as simple as possible so that I can under stand.   
  Use the Settings class.Using Settings in C#;Quote:Original post by Justin RebuiltUse the Settings class.Using Settings in C#That a Page I all ready read threw and didn't under stand a thing.;  I'm not sure how much simpler it can get than that page.I'm guessing your smtpServer and smtpPort variables are being obtained from TextBox components? You can get the value of them by using the Text or Value property, depending on what type of component they are.After you get the values, simply set the settings values and save them using the Settings class.Properties.Settings.Default.smtpServer = TextBox1.ValueProperties.Settings.Default.smtpPort = TextBox2.ValueProperties.Settings.Default.Save();Obviously you change the variable names to match your own.   ;Quote:Original post by Justin RebuiltI'm not sure how much simpler it can get than that page.I'm guessing your smtpServer and smtpPort variables are being obtained from TextBox components? You can get the value of them by using the Text or Value property, depending on what type of component they are.After you get the values, simply set the settings values and save them using the Settings class.Properties.Settings.Default.smtpServer = TextBox1.ValueProperties.Settings.Default.smtpPort = TextBox2.ValueProperties.Settings.Default.Save();Obviously you change the variable names to match your own.Well This is what I have. and well that part I do under stand.Heres my settings. This in what I have for the save.Properties.Settings.Settings.SmtpServer = TextBox1.Value1Properties.Settings.Settings.SmtpPort = TextBox2.Value2Properties.Settings.Settings.Save();What I'm trying to point out is that how do I load the current setting in to be displayed on the screen or form. I have form3 that displays or should display the current setting and then the user has an option of changing one or the other or even both.I Have TextBox1.Text = SmtpServer; // For the SmtpServer Addressand I have TextBox2.Text = SmtpPort; // For the Port numberI just want to display the current setting.And it tells me that they are not definded.Then I can useif (TextBox1.Text <> ""){Properties.Settings.Settings.SmtpServer = TextBox1.Value1}This will tell if the Value1 is blank or not and if the field is not bank then it will update it.and then I can save it. ;  The compiler is telling you what's wrong. You haven't defined SmtpServer and SmtpPort. If you're trying to retrieve them from settings:Example:int SmtpPort = Properties.Settings.Default.SmtpPort;   ;Quote:Original post by Justin RebuiltThe compiler is telling you what's wrong. You haven't defined SmtpServer and SmtpPort. If you're trying to retrieve them from settings:Example:int SmtpPort = Properties.Settings.Default.SmtpPort;Thank You I was missing the Default part. One more thingOn this lineProperties.Settings.Default.SmtpPort = Value2.Text;Witch is an INT for the port being used. I get this error. and Yes I know what this error is.Error1Cannot implicitly convert type 'string' to 'int'How Can I process it as a string.;  Use something like if (!int.TryParse(Value2.Text, out Properties.Settings.Default.SmtpPort)){  // Conversion failed - do something sensible like warn the user.};Quote:Original post by TheUnbelieverUse something like if (!int.TryParse(Value2.Text, out Properties.Settings.Default.SmtpPort)){  // Conversion failed - do something sensible like warn the user.}Thank You now I have a new errorError1A property or indexer may not be passed as an out or ref So Heres my code. All of it.  public partial class Form3 : Form    {   public Form3()   {  InitializeComponent();   }   private void Form3_Load(object sender, EventArgs e)   {  // Load Current setting for Smtp Settings  String SmtpServer = Properties.Settings.Default.SmtpServer;  int SmtpPort = Properties.Settings.Default.SmtpPort;    label2.Text = SmtpServer;    //label3.Text = SmtpPort;  // I need to display the INT in the label3   }   private void button2_Click(object sender, EventArgs e)   {  // User Aborts Save  this.Close();   }   private void button1_Click(object sender, EventArgs e)   {  // User Updates and saves New Setting;;  if (Value1.Text != "")   {  Properties.Settings.Default.SmtpServer = Value1.Text;  }  if (Value2.Text != "")  { if (!int.TryParse(Value2.Text, out Properties.Settings.Default.SmtpPort)) { // Conversion failed - do something sensible like warn the user. // I put a Message Box here }  } // Save The enties if any Properties.Settings.Default.Save(); this.Close(); }    };  Sorry, that's my fault for not checking. Properties.Settings.Default.SmtpPort is a property (a single (or pair of) function(s) that act(s) like a field (a member variable), and you can't pass that in as a out parameter because it's not really a field so there's nothing 'real' to pass as a reference.int smtpPort = Properties.Settings.Default.SmtpPort;if (!int.TryParse(Value2.Text, out smtpPort)){  // Conversion failed - do something sensible like warn the user.}Properties.Settings.Default.SmtpPort = smtpPort;