Cleaven
Cleaven

Reputation: 974

Not all dynamic labels are being created

I have four labels that need to be created and placed dynamically, however, only the first two are being created and placed.

Here is the code:

int x = 10; int y = 50;
pnlRepShow.Controls.Add(new Label { Text = "Product Name:", Height = 40, Width = 100, Name = "Label" + y, Location = new Point(x, y) });

pnlRepShow.Controls.Add(new Label { Text = "Previous Stock:", Height = 40, Width = 100, Name = "Label" + y, Location = new Point(x, y + 100) });

pnlRepShow.Controls.Add(new Label { Text = "Current Stock:", Height = 40, Width = 100, Name = "Label" + y, Location = new Point(x, y + 100) });

pnlRepShow.Controls.Add(new Label { Text = "Difference:", Height = 40, Width = 100, Name = "Label" + y, Location = new Point(x, y + 100) });

Here is the output:

Display

Please help.

Upvotes: 0

Views: 24

Answers (1)

hawkeyegold
hawkeyegold

Reputation: 129

You are using the same x and y location for your second, third and fourth labels. This is causing them to be stacked on top of each other, appearing visually as if only the first two are actually being created. Change your x or y values for the third and fourth ones so that all four combinations are unique and your problem will be solved.

Upvotes: 1

Related Questions