c#窗口中添加了两个panel控件,第二个没有办法显示出来?新手求助????
总共是循环两次,panel[0]正常显示,而panel【1】显示不出来,可是实验后发现窗口中存在Panel[1],而且panel[1]中也有东西,这是怎么回事????????????????
Panel[] panel = new Panel[totalNumber];
//将问题和选项使用一个循环进入窗口和控件中
//ferry变量存放现在是第几次循环
int ferry = 0;
while (reader.Read())
{
//设置panel的属性
panel[ferry] = new Panel();
panel[ferry].Width = 412;
panel[ferry].Height = 40;
panel[ferry].Location = new Point(0,30+ferry*40);
int width = panel[ferry].Width / 4;
int height = panel[ferry].Height / 2;
this.Controls.Add(panel[ferry]);
//title变量存放题目
string title = reader.GetString(3);
//change变量存放选项
string[] change = new string[4];
for (int i = 0; i < 4; i++)
{
int a = 4+i;
change[i] = reader.GetString(a);
}
RadioButton[] radiobtn = new RadioButton[4];
//进行题目位置和大小的初始化
TextBox textbox = new TextBox();
textbox.Text = title;
textbox.ReadOnly = true;
textbox.BorderStyle = System.Windows.Forms.BorderStyle.None;
textbox.Height = height;
textbox.Width = panel[ferry].Width;
textbox.Location = new Point(0,ferry*panel[ferry].Height);
//将题目添加入panel
panel[ferry].Controls.Add(textbox);
//设置radiobutton的长和高
for (int i = 0; i < 4; i++)
{
radiobtn[i] = new RadioButton();
radiobtn[i].Text = change[i];
radiobtn[i].Name = "panel" + ferry.ToString();
radiobtn[i].Location = new Point(i * width, height + ferry * panel[ferry].Height);
radiobtn[i].Width = width;
radiobtn[i].Height = height;
panel[ferry].Controls.Add(radiobtn[i]);
}
++ferry;
}