P
P
Parsifal1122021-04-14 16:23:02
C++ / C#
Parsifal112, 2021-04-14 16:23:02

When a button is pressed, a new button appears. How to make it so that when the child buttons are pressed, the buttons also appear?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace fjaslkfj
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private Button[] buttons = new Button[50];
        public int i = 0;
        private void Button1_Click(object sender, EventArgs e)
        {
            buttons[i] = new Button();
            this.SuspendLayout();
            buttons[i].Location = new Point(76 * i, 25);
            buttons[i].Size = new Size(75, 25);
            buttons[i].Text = Convert.ToString(i + 1);
            this.Controls.Add(buttons[i]);
            this.ResumeLayout();
            i++;
        }
    }
}

tell me how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cicatrix, 2021-04-14
@cicatrix

buttons[i].Click += Button1_Click; // или другой обработчик нажатия

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question