Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3. List<Button> buttons = new List<Button>();
  4. Button btn;
  5. int x = 0;
  6.  
  7. private void yourMethod(object sender, EventArgs e)
  8. {
  9. this.Text = "Hello";
  10. }
  11.  
  12.  
  13. public Form1()
  14. {
  15. InitializeComponent();
  16. }
  17.  
  18. private void button1_Click(object sender, EventArgs e)
  19. {
  20. //создание кнопки
  21. x += 70;
  22. btn = new Button();
  23. btn.Text = "b" + x;
  24. btn.Left = x;
  25. btn.Top = 100;
  26. btn.Height = 50;
  27. btn.Width = 50;
  28. this.Controls.Add(btn);
  29. //добавляем событие
  30. btn.Click += new EventHandler(yourMethod);
  31.  
  32. //добавляем в коллекцию
  33. buttons.Add(btn);
  34.  
  35. //выводим количество
  36. label1.Text = buttons.Count.ToString();
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement