如何将面板添加到另一个面板

How to add panel into another panel

我想在单击 button1 时将其中一个 panel1,2,... 添加到 panel0 中。

这是我的代码

private void button3_Click(object sender, EventArgs e)
        {
            int i = 0;
            int j = 0;


            Panel[] pnl = new Panel[3];

            while ( i<2)
            {
                pnl[i].Parent = panel0;                  // erorr

                pnl[i].BackColor = Color.PeachPuff;

                pnl[i].Size = new Size(50, 10);
                pnl[i].Location = new Point(j+5,10);
                panel0.Controls.Add(pnl[i]);
                pnl[i].BringToFront();

                i++;
                j = j + 13;
            }
         }

有什么建议吗?

将面板[] pnl = 新面板[3] 更改为:

var pnl  = new List<Panel>{existingPanel1, existingPanel2, existingPanel3};