title: C# - How to register onMouseClick in real time?
body: <p>I am writing a silly little program (as we all do from time to time) to work on some basic C# coding.  As I'm sure you can see, the mouse is clicked, the picture moves until it's at the place where the mouse was clicked.  This bit works fine.  I then want the picturebox to move randomly, which I have also managed!  The next problem I have is that when I click, instead of moving to the new mouse coordinates, the picturebox continues to move randomly.  Any help on this would be much appreciated!  Here is the code I think is the problem.</p>
  
  <p>Many Thanks!</p>
  
  <p>John</p>
  
  <pre><code>protected override void OnMouseClick(MouseEventArgs e)
  {
      base.OnMouseClick(e);
      int destX = e.X;
      int destY = e.Y;
  
          HasArrived = false;
  
      while (HasArrived == false)
      {
      moveImage(destX, destY, pictureBox1);
  
          if (pictureBox1.Left == destX &amp;&amp; pictureBox1.Top == destY)
          {
              HasArrived = true;
              while (HasArrived == true)
              {
                  randomMove(pictureBox1);
                  hungry1 += 1;
              }
          }
      }
  }
  </code></pre>