I was wondering if somebody could help me improve my code (?)
Three weeks ago I decided that it would be very useful to learn C#/C++ (decided to start with c#) and I'm doing my best, but I have problems with understanding some basics- for example arrays.
I would like to add "x" textboxes (where "x" is the value form numericUpDown) with a button click.
I found a solution how to do this, but I have this feeling that it is possible to write this in a different (better) way ( I assume advanced programers would use lists or arrays).
Please forgive me if I'm wrong, as I mentioned before- I'm new and doing my best to learn.
Here is my code:
private void button1_Click(object sender, EventArgs e) { if (numericUpDown1.Value == 1) { txtbx1.AutoSize = true; Controls.Add(txtbx1); txtbx1.Location = new Point(70, 100); } else if (numericUpDown1.Value == 2) { txtbx1.AutoSize = true; Controls.Add(txtbx1); txtbx1.Location = new Point(70, 100); txtbx2.AutoSize = true; Controls.Add(txtbx2); txtbx2.Location = new Point(70, 130); } else if (numericUpDown1.Value == 3) { txtbx1.AutoSize = true; Controls.Add(txtbx1); txtbx1.Location = new Point(70, 100); txtbx2.AutoSize = true; Controls.Add(txtbx2); txtbx2.Location = new Point(70, 130); txtx3.AutoSize = true; Controls.Add(txtbx3); txtbx3.Location = new Point(70, 160); } }
code reviewcodereview.stackexchange.comswitchstatements