The task when you click on the button to create another button with a specific color of the button. Add a button to the form when clicked, we create a button with the specified color.
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); // Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ Π½Π° ΡΠΎΡΠΌΡ } When you click on the buttonDynamic button, a new button appears, but its color is standard gray. What am I doing wrong?