title: Picture box background image not refreshing
body: <p>I have some buttons in a panel1 and depending on the duration (no. of ticks) between the MouseDown and MouseUp event a picture is displayed in panel2. The button pressed determines the location of the picture. The program is working fine when each button is pressed for the first time.
  The problem occurs when a button is pressed for the second time becuase the image would not change. E.g. button1 is pressed, 4 ticks are counted and pic A is displayed.....
               button1 is pressed again, 7 ticks are counted and pic B should be displayed instead of pic A but problem is that pic A stays there!
  I think it has something to do with the OnPaint method but after several tries I was not able to fix the problem, any suggestion are welcome... Tks</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Drawing;
  
  namespace SimplePiano
  {
      class MusKey : Panel
      {
              protected int duration;
              public int musicNote;
              public TextBox txt1 = new TextBox(); //To test if musicNote refers to the correct pitch integer.
              public TextBox txt2 = new TextBox(); //To test the number of ticks.
              protected Timer timer = new Timer();
  
              public MusKey(int iNote, int x, int y): base()
              {
                  musicNote = iNote;
                  this.Location = new Point(x, y);
                  this.Size = new Size(50, 200);
                  this.BackColor = Color.White;
                  this.BorderStyle = BorderStyle.FixedSingle;
                  this.Visible = true;
  
                  this.MouseDown += new MouseEventHandler(this.MusKey_MouseDown);
                  this.MouseUp += new MouseEventHandler(this.MusKey_MouseUp);
              }
  
              protected void MusKey_MouseDown(object sender, EventArgs e)
              {
                  duration = 0;
                  timer.Interval = 100;
                  timer.Tick += new EventHandler(timer1_Tick);
                  txt1.Text = Convert.ToString(musicNote)+" down"; //To test if musicNote refers to the correct pitch integer.
                  timer.Tick += new EventHandler(timer1_Tick);
                  timer.Enabled = true;
                  timer.Start();
                  duration = 0;
              }
  
              protected void MusKey_MouseUp(object sender, EventArgs e)
              {
                  timer.Stop();
                  txt1.Text = Convert.ToString(musicNote)+ " up"; //To test if musicNote refers to the correct pitch integer.
                  txt2.Text = Convert.ToString(duration);         //To test the number of ticks.
                  timer.Enabled = false;
                  string bNoteShape = "";
  
                  if (duration &lt; 5) bNoteShape = "Crotchet.png";
                  if (duration &gt; 5) bNoteShape = "minim.png";
                  MusicNote musNote = new MusicNote(this.musicNote, bNoteShape);
  
                  Form1.Ms.Controls.Add(musNote);
  
              }
  
              private void timer1_Tick(object sender, EventArgs e)
              {
                  duration++;
              }
      }
  }
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Drawing;
  
  namespace SimplePiano
  {
      public class MusicNote: PictureBox
      {
          public string path = "";
          public int pitch; //The no. of the music key (e.g. the sound freuency).
          public string noteShape; //Mapped to a note shape(e.g. Crotchet, Minim, Quaver etc.)
          public int noteDuration;
  
          public MusicNote(int iPitch, string iNoteShape):base()
          {
              pitch = iPitch;
              noteShape = iNoteShape;
              Location = new Point((pitch*40)-40, 100);
              Size = new Size(40, 40);
              //Bitmap bmp = new Bitmap(noteShape + ".png");
              BackgroundImage = Image.FromFile(noteShape);
              this.BackColor = Color.Transparent;
              Image = Image;
              this.Visible = true;
              this.BringToFront();
          }
  
          protected override void OnPaint(PaintEventArgs pe)
          {
              base.OnPaint(pe);
          }
      }
  }
  </code></pre>