Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. int number = int.Parse(textBox3.Text);
  4. Button[] textBoxes = new Button[number];
  5. int location = 136;
  6.  
  7. for (int i = 0; i < textBoxes.Length; i++)
  8. {
  9. location += 81;
  10. var txt = new Button();
  11. textBoxes[i] = txt;
  12. txt.Name = "text" + i.ToString();
  13. txt.Text = "textBox" + i.ToString();
  14. txt.Location = new Point(location, 124);
  15. txt.Visible = true;
  16. this.Controls.Add(txt);
  17. }
  18. }
  19.  
  20. class Form1 : Form {
  21. private Button[] _textBoxes;
  22.  
  23. private void button2_Click(object sender, EventArgs e) {
  24. int number = int.Parse(textBox3.Text);
  25. if(_textBoxes != null) {
  26. foreach(Button b in _textBoxes)
  27. this.Controls.Remove(b);
  28. }
  29.  
  30. _textBoxes = new Button[number];
  31. int location = 136;
  32.  
  33. for (int i = 0; i < textBoxes.Length; i++) {
  34. location += 81;
  35. var txt = new Button();
  36. _textBoxes[i] = txt;
  37. txt.Name = "text" + i.ToString();
  38. txt.Text = "textBox" + i.ToString();
  39. txt.Location = new Point(location, 124);
  40. txt.Visible = true;
  41. this.Controls.Add(txt);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement