2D mark doesn't work

I have this code to display 81 labels in a table. But when I try to write the code, it doesn't display all the labels. can anyone tell me where is the problem?

Label[,] val = new Label[9,9];
        Point p = new Point();
        p.X = 300;
        p.Y = 300;
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                val[i, j] = new Label();
                val[i, j].Location = p;
                p.X = p.X + 20;
                val[i, j].Text = i.ToString();
                this.Controls.Add(val[i, j]);
            }
            p.Y = p.Y + 50;
        }

      

+3


source to share


2 answers


You are using SAME POINT structure



+3


source


As HungPV pointed out,

you are using SAME POINT object



Try the following:

Label[,] val = new Label[9, 9];

int X = 0;
int Y = 0;
for (int i = 0; i < 9; i++)
{
    for (int j = 0; j < 9; j++)
    {
      val[i, j] = new Label();
      val[i, j].Location = new Point(X,Y);
      X +=  20;
      val[i, j].Text = "Row: " + i +"Column: " + j;
      Controls.Add(val[i, j]);
    }
    Y += 50;
}

      

+3


source







All Articles