Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static int X = 100;
- private static int Y = 100;
- private void buttonDynamic_Click(object sender, EventArgs e)
- {
- AddButton(X, Y);
- X += 100;
- }
- private void AddButton(int x, int y)
- {
- // создаем контрол
- System.Windows.Forms.Button buttonDyn = new System.Windows.Forms.Button();
- // устанавливаем необходимые свойства
- buttonDyn.Location = new System.Drawing.Point(x, y);
- buttonDyn.Name = "button1";
- buttonDyn.Size = new System.Drawing.Size(75, 23);
- buttonDyn.TabIndex = 0;
- //вот здесь меняем цвет кнопки
- buttonDyn.BackColor = Color.Chartreuse;
- buttonDyn.UseVisualStyleBackColor = true;
- // button1_Click - функция обработчик события нажатия на кнопку
- buttonDyn.Click += new System.EventHandler(button1_Click);
- Controls.Add(buttonDyn); // добавляем на форму
- }
- Controls.Add(buttonDyn);
- buttonDyn.BackColor = Color.Chartreuse;
Add Comment
Please, Sign In to add comment