0
\$\begingroup\$
InitializeComponent();

            Label[] labels = new Label[4];
            for(int i = 0; i < labels.Length; i++)
            {
                labels[i] = new Label();
                labels[i].Text = i.ToString();
                labels[i].Location = new Point(0, i * 30);
                this.Controls.Add(labels[i]);
            }

this will display 0, 1, 2 ,3 but I want to display 1, 2 ,3 ,4 and still make the first one at the location 0,0 and the rest with gap on the y double by 30

\$\endgroup\$
1
  • 6
    \$\begingroup\$ Could this be like labels[i].Text = (i+1).ToString(); ? This seems more like a general programming question, not specifically gamedev \$\endgroup\$
    – Alex CB
    Aug 17, 2023 at 12:03

1 Answer 1

3
\$\begingroup\$

Create a new variable which is 1 more than i, so it should look like this:

InitializeComponent();

            Label[] labels = new Label[4];
            for(int i = 0; i < labels.Length; i++)
            {
                labels[i] = new Label();
                int j = i+1;
                labels[i].Text = j.ToString();
                labels[i].Location = new Point(0, i * 30);
                this.Controls.Add(labels[i]);
            }
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .