title: Evading button, but in a clean way
body: <p>I am making a test program in C# to learn about WinForms. The principle is, I have a UserControl of 640x480, with a button. When the cursor approach the button, I move it away.</p>
  
  <p>I also detect when the button is dangerously near the limits of the UserControl, and make the button "jump" on the other side of the cursor, but is there a way to make it in a clean way (the button move escaping the cursor, without going out of the winform, and toward the center ?)</p>
  
  <p>Current handling of UserControl's MouseMove event:</p>
  
  <p>nX, nY, lastX, lastY are private int declared in the class.</p>
  
  <pre><code>private void UserControl1_MouseMove(object sender, MouseEventArgs e)
      {
          if(
              e.X &lt; (this.button1.Location.X + this.button1.Size.Height  + 20) &amp;&amp;
              e.Y &lt; (this.button1.Location.Y + this.button1.Size.Width + 20) &amp;&amp; 
              e.X &gt;= (this.button1.Location.X - 20) &amp;&amp; 
              e.Y &gt;= (this.button1.Location.Y - 20)
          )
          {
              nX = this.button1.Location.X + (e.X - lastX);
              nY = this.button1.Location.Y + (e.Y - lastY);
              if (nX &lt; 20)
              {
                  nX = nX + 80;
              }
              if (nY &lt; 20)
              {
                  nY = nY + 80;
              }
              if (nX &gt; this.Size.Width - this.button1.Size.Width - 20)
              {
                  nX = nX - 80;
              }
              if (nY &gt; this.Size.Height - this.button1.Size.Height - 20)
              {
                  nY = nY - 80;
              }
              this.button1.Location = new System.Drawing.Point(nX, nY);
          }
          lastX = e.X;
          lastY = e.Y;
      }
  </code></pre>