在 Form 构造函数中,我生成了一个面板数组(下面代码中的pnl_),其中包括单选按钮。当我可视化表单时,只有面板可见,而不是内部的单选按钮。奇怪的是,当我只生成一个面板(下面代码中的pnl )时,一切都很好。
public partial class Radiobuttons_on_Panel : Form
{
private Panel pnl = new Panel();
private RadioButton rbtn1 = new RadioButton();
private RadioButton rbtn2 = new RadioButton();
private Panel[] pnl_ = new Panel[7];
private RadioButton[] rbtn1_ = new RadioButton[7];
private RadioButton[] rbtn2_ = new RadioButton[7];
public Radiobuttons_on_Panel()
{
InitializeComponent();
pnl.Location = new Point(10, 10);
pnl.Size = new Size(100, 100);
pnl.BorderStyle = BorderStyle.FixedSingle;
rbtn1.Location = pnl.Location;
rbtn1.Text = "AAA";
rbtn2.Location = new Point(pnl.Location.X, pnl.Location.Y + rbtn1.Height);
rbtn2.Text = "BBB";
pnl.Controls.Add(rbtn1);
pnl.Controls.Add(rbtn2);
this.Controls.Add(pnl);
for (int i = 0; i < pnl_.Length; i++)
{
pnl_[i] = new Panel();
pnl_[i].BorderStyle = BorderStyle.FixedSingle;
pnl_[i].Size = new Size(100, 100);
pnl_[i].Location = new Point(10 + i * 110, 200);
rbtn1_[i] = new RadioButton();
rbtn1_[i].Location = pnl_[i].Location;
rbtn1_[i].Text = "AAA";
rbtn2_[i] = new RadioButton();
rbtn2_[i].Location = new Point(pnl_[i].Location.X, pnl_[i].Location.Y + rbtn1_[i].Height);
rbtn2_[i].Text = "BBB";
pnl_[i].Controls.Add(rbtn1_[i]);
pnl_[i].Controls.Add(rbtn2_[i]);
this.Controls.Add(pnl_[i]);
}
}
}
问题出在哪里?