title: Trying to draw rectangles on click
body: <p>So I've been self teaching c# and following tutorials. Up until this time there was no major problems. Bun now i cant find solution on my own.</p>
  
  <p>So i got a listing of a simple form that's supposed to create rectangles and attractor points on different mouse clicks. But when I run the code, nothing happens.</p>
  
  <p>I cant understand what is wrong.. please help (=</p>
  
  <pre><code>public partial class Form1 : Form
  {
  
      float mRectSize = 50;
      List&lt;RectangleF&gt; mRectangles = new List&lt;RectangleF&gt;();
      Random rnd = new Random();
      PointF mForcePoint = new PointF(-1, -1);
      bool mForcePush = false;
      int mRandomSeed = 10;
  
      public Form1()
      {
          InitializeComponent();
          Timer timer1 = new Timer();
          timer1.Interval = 1;
          timer1.Tick += Timer1_Tick;
          timer1.Start();
  
  
      }
  
      private void AddRectangle(PointF pos)
      {
  
          mRectangles.Add(new RectangleF(pos.X - mRectSize / 2, pos.Y - mRectSize / 2, mRectSize, mRectSize));
      }
  
      private void AddForcePoint(PointF pos)
      {
          mForcePoint = pos;
      }
  
      private void DrawRectangle(Graphics g, RectangleF rect)
      {
          Color c = Color.FromArgb(255, rnd.Next(255), rnd.Next(255), rnd.Next(255));
          g.FillRectangle(new SolidBrush(c), rect);
      }
  
      private PointF RandomiseDirection(PointF dir)
      {
          dir.X += rnd.Next(2 * mRandomSeed) - mRandomSeed;
          dir.Y += rnd.Next(2 * mRandomSeed) - mRandomSeed;
  
          return dir;
      }
  
      private void Form1_Paint(object sender, PaintEventArgs e)
      {
          Graphics g = e.Graphics;
  
          foreach (RectangleF rect in mRectangles)
          {
              DrawRectangle(g, rect);
          }
      }
  
      private void Form1_MouseDown(object sender, MouseEventArgs e)
      {
          if (e.Button == System.Windows.Forms.MouseButtons.Left)
          {
              AddRectangle(e.Location);
              //MessageBox.Show("test");
              Invalidate();
          }
  
          if (e.Button == System.Windows.Forms.MouseButtons.Right)
          {
              AddForcePoint(e.Location);
          }
  
          if (e.Button == System.Windows.Forms.MouseButtons.Middle)
          {
              mForcePush = !mForcePush;
          }
  
      }
  
      private void Timer1_Tick(object sender, EventArgs e)
      {
          if (mForcePoint.X != -1 &amp;&amp; mForcePoint.Y != -1)
          {
              for (int i = 0; i &lt; mRectangles.Count; i++)
              {
                  RectangleF rect = mRectangles[i];
  
                  PointF direction = new PointF(mForcePoint.X - rect.Location.X, mForcePoint.Y - rect.Location.Y);
  
                  direction = RandomiseDirection(direction);
  
                  if (mForcePush)
                  {
                      rect.Location = new PointF(rect.Location.X - direction.X * 0.1f, rect.Location.Y - direction.Y * 0.1f);
                  }
  
                  else
                  {
                      rect.Location = new PointF(rect.Location.X + direction.X * 0.1f, rect.Location.Y + direction.Y * 0.1f);
                  }
  
                  mRectangles[i] = rect;
  
              }
  
              Invalidate();
  
          }
      }
  }
  </code></pre>
  
  <p>}</p>