0

I'm working on a dynamic button on the c# form screen, but I'm having a problem somewhere. My problem is the following: I want to produce click methods specific to each button I create dynamically. That is, I want each button to have its own code. I don't know how to do this and I found solutions on the internet like the example below, but they don't solve my problem.

        List<Button> buttons = new List<Button>();

        private void deneme_Load(object sender, EventArgs e)
        {
            butonGoster();
        }


        public void butonGoster()
        {

            for (int i = 0; i < 5; i++)
            {
                Button btn = new Button();
                btn.Text = i.ToString();
                btn.Location = new Point(40, 40 * (i + 1));
                Controls.Add(btn);
                btn.MouseClick += btn_Click;
                buttons.Add(btn);
            }
        }

        private void btn_Click(object sender, EventArgs e)
        {
            if (sayac == 1)
                MessageBox.Show("yarrams");

        }

The solution I found here does not work for me

Is there a solution that looks like this : btn.MouseClik += new MouseEventHandler( { codes } ); ?

Krig343
  • 17
  • 10

0 Answers0