title: How do I close an image open in a picturebox so I can delete it?
body: <p>at the moment my form has a system where i can save the data in the form to a directory in the applications folder then load it again through a listbox i have set up now i need to add a delete button to delete the data out of the folder the problem is if i opened it it returns an error cannot delete  because the file is in use heres the code i use to save the data</p>
  
  <pre><code>    private void button3_Click(object sender, EventArgs e)
      {
              using (var writer = new StreamWriter(@"cards\" + CardName.Text + ".card", false))
              {
                  int lev = Level.SelectedIndex;
                  int race = Race.SelectedIndex;
                  int attribute = CardAttribute.SelectedIndex;
                  int cardtype = comboBox1.SelectedIndex;
                  int monstertype = comboBox2.SelectedIndex;
                  int spelltype = comboBox4.SelectedIndex;
                  int traptype = comboBox3.SelectedIndex;
                  String[] des = CardDescription.Text.Split('\n');
                  ImageConverter img_converter = new ImageConverter();
                  byte[] bytes = (byte[])img_converter.ConvertTo(IMG, typeof(byte[]));  
                  File.WriteAllBytes(@"cards\" + CardName.Text + ".jpg", bytes);
                  writer.WriteLine("#ID:" + CardID.Text);
                  writer.WriteLine("#lev:" + lev);
                  writer.WriteLine("#rac:" + race);
                  writer.WriteLine("#att:" + attribute);
                  writer.WriteLine("#atk:" + ATK.Text);
                  writer.WriteLine("#def:" + DEF.Text);
                  writer.WriteLine("#pic:" + CardName.Text + ".jpg");
                  writer.WriteLine("#ctp:" + cardtype);
                  writer.WriteLine("#mtp:" + monstertype);
                  writer.WriteLine("#stp:" + spelltype);
                  writer.WriteLine("#ttp:" + traptype);
                  writer.WriteLine("#gol:" + checkBox1.Checked);
                  writer.WriteLine("#nam:" + CardName.Text);
                  foreach (string l in des)
                  {
                      writer.WriteLine("#des:" + l);
                  }
              }
              ListUpdate();
          }
  </code></pre>
  
  <p>to load the data</p>
  
  <pre><code>    private void listBox1_DoubleClick(object sender, EventArgs e)
      {
          string open = @"cards\" + listBox1.SelectedItem.ToString() + ".card";
          var reader = new StreamReader(File.OpenRead(open));
          while (!reader.EndOfStream)
          {
              string line = reader.ReadLine();
              if (line.StartsWith("#ID:"))
              {
                  CardID.Text = line.Substring(4);
              }
              if (line.StartsWith("#lev:"))
              {
                  string lev = line.Substring(5);
                  Level.SelectedIndex = Convert.ToInt32(lev);
              }
              if (line.StartsWith("#rac:"))
              {
                  string rac = line.Substring(5);
                  Race.SelectedIndex = Convert.ToInt32(rac);
              }
              if (line.StartsWith("#att:"))
              {
                  string att = line.Substring(5);
                  CardAttribute.SelectedIndex = Convert.ToInt32(att);
              }
              if (line.StartsWith("#atk:"))
              {
                  ATK.Text = line.Substring(5);
              }
              if (line.StartsWith("#def:"))
              {
                  DEF.Text = line.Substring(5);
              }
              if (line.StartsWith("#ctp:"))
              {
                  string ctp = line.Substring(5);
                  comboBox1.SelectedIndex = Convert.ToInt32(ctp);
              }
              if (line.StartsWith("#mtp:"))
              {
                  string mtp = line.Substring(5);
                  comboBox2.SelectedIndex = Convert.ToInt32(mtp);
              }
              if (line.StartsWith("#stp:"))
              {
                  string stp = line.Substring(5);
                  comboBox4.SelectedIndex = Convert.ToInt32(stp);
              }
              if (line.StartsWith("#ttp:"))
              {
                  string ttp = line.Substring(5);
                  comboBox3.SelectedIndex = Convert.ToInt32(ttp);
              }
              if (line.StartsWith("#gol:"))
              {
                  string gold = line.Substring(5);
                  checkBox1.Checked = Convert.ToBoolean(gold);
              }
              if (line.StartsWith("#nam:"))
              {
                  CardName.Text = line.Substring(5);
              }
              if (line.StartsWith("#des:"))
              {
                  des += line.Substring(5) + Environment.NewLine;
                  CardDescription.Text = des;
              }
              if (line.StartsWith("#pic:"))
              {
                  if (File.Exists(@"cards\" + line.Substring(5)))
                  {
                      IMG = Image.FromFile(@"cards/" + line.Substring(5));
                  }
              }
          }  
          des = "";
          GenerateCard();
      }
  </code></pre>
  
  <p>and to delete it</p>
  
  <pre><code>    private void button4_Click(object sender, EventArgs e)
      {
          string list = listBox1.SelectedItem.ToString();
          if (File.Exists(@"cards\" + list + ".card"))
          {
              File.Delete(@"cards\" + list + ".card");
          }
          if (File.Exists(@"cards\" + list + ".jpg"))
          {
              File.Delete(@"cards\" + list + ".jpg");
          }
          ListUpdate();
      }
  </code></pre>