Search code examples
c#arrayspoint

PointF array has all values the same


On every new click I get new coordinates and save them in points but it also changes old values. For example

First click: points[(156, 25), (0, 0), (0, 0)]

Second click: points[(85, 92), (85, 92), (0, 0)]

Third click: points[(15, 120), (15, 120), (15, 120)]

PointF[] points = new PointF[3];
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
   points[angle] = new PointF(Location.X, Location.Y);
   angle++;
}

Solution

  • You should use e.X and e.Y, not Location, because Location is the Location of the form.