title: How to store ListBox items into the file and retrive them back?
body: <p>I'm working on storing last used settings and then when program starts retrieve them back. Everything works fine but I just don't know how to deal with ListBox items.</p>
  
  <p>To point out one thing is that I'm already using one delimiter to store my settings. I'm getting quite confused when dealing with this problem.</p>
  
  <p>This is how I store my settings:</p>
  
  <pre><code>private void btnStart_Click(object sender, EventArgs e)
  {
      int interval = 0;
      int plusMinus = 0;
      int pause = 0;
      int delay = 0;
      int randomLine = 0;
  
      if (cbPause.Checked == true) pause = 1;
      if (cbDelay.Checked == true) delay = 1;
      if (cbRandomLine.Checked == true) randomLine = 1;
      interval = int.Parse(nudInterval.Value.ToString());
      plusMinus = int.Parse(nudPlusMinus.Value.ToString());
  
      lastUsed.Text = 
          interval + splitString + 
          plusMinus + splitString + 
          pause + splitString + 
          delay + splitString + 
          randomLine;
  
      if (nudPlusMinus.Value == 0)
      {
          tmrInterval.Interval = int.Parse(nudInterval.Value.ToString());
      }
      else
      {
          Random random = new Random();
          tmrInterval.Interval = random.Next(int.Parse(nudInterval.Value.ToString()) - int.Parse(nudPlusMinus.Value.ToString()), int.Parse(nudInterval.Value.ToString()) + int.Parse(nudPlusMinus.Value.ToString()));
      }
  
      WhenStarted();
  
      tmrInterval.Start();
  }
  </code></pre>
  
  <p>This is how I retrieve them at the program start up:</p>
  
  <pre><code>public AutoTyper()
  {
      InitializeComponent();
  
      tmrInterval.Tick += new EventHandler(Interval);
      tmrDelay.Tick += new EventHandler(Delay);
      tmrSpace.Tick += new EventHandler(Space);
  
      lbMessage.SelectedIndexChanged += new EventHandler(lbMessage_SelectedIndexChanged);
      txtMessage.TextChanged += new EventHandler(txtMessage_TextChanged);
  
      SetInterval();
  
      if (!lastUsed.EmptyFile())
      {
          string[] allSettings = lastUsed.Text.Split(splitChar, StringSplitOptions.None);
          int settingCount = 0;
          int settingNumber = 0;
  
          foreach (string setting in allSettings) settingNumber++;
  
          if (settingNumber == 5)
          {
              foreach (string setting in allSettings)
              {
                  settingCount++;
  
                  if (settingCount == 1) nudInterval.Value = int.Parse(setting);
                  else if (settingCount == 2) nudPlusMinus.Value = int.Parse(setting);
                  else if (settingCount == 3) { if (setting == "1") cbPause.Checked = true; }
                  else if (settingCount == 4) { if (setting == "1") cbDelay.Checked = true; }
                  else if (settingCount == 5) { if (setting == "1") cbRandomLine.Checked = true; }
              }
          }
      }
  }
  </code></pre>