Hello guys. I have queries, i made a matrix of Buttons and another of Panels and everythings is ok, that works. There is the code:

 private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                {
                    ci = i;
                    cj = j;
                    M[i, j] = new Button(); 
                    panel1.Controls.Add(M[i, j]);
                    this.M[i, j].Location = new Point(10 + i * 100, 10 + j * 100);
                    this.M[i, j].Size = new Size(80, 80);
                    P[i, j] = new Panel();
                    panel1.Controls.Add(P[i, j]);
                    this.P[i, j].Location = new Point(10 + i * 100, 10 + j * 100);
                    this.P[i, j].Size = new Size(80, 80);
                    this.P[i, j].BackColor = Color.Red;
                    this.M[i, j].Click +=new EventHandler(ClickButton);
                }
        }

BUT, i want to make an event for Button which act on coresponding panel. So there is the problem.. I don't know how to do this.. I tried something but no change.
Anybody can help me? :(

Recommended Answers

All 3 Replies

You are adding all the panels to panel1 and all the buttons to panel1. If you added the buttons to the panel it is to affect, then you could use the buttons Parent property to get the panel you need.

good point, i'll try this.

thanks man, that works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.