c#窗口中添加了两个panel控件,第二个没有办法显示出来?新手求助????

zhangxinleehom 2014-06-09 07:47:30
总共是循环两次,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;
}
...全文
638 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
恭喜楼主解决问题
tanta 2014-06-09
  • 打赏
  • 举报
回复
多跟踪,调试,时间长了就会好的。
  • 打赏
  • 举报
回复
zhangxinleehom 2014-06-09
  • 打赏
  • 举报
回复
解决了,POint中的位置应该是相对的位置,就是相对与panel的位置,还是谢谢你的回答
zhangxinleehom 2014-06-09
  • 打赏
  • 举报
回复
确定两次,而且两个panel也没有重叠,我都吧他们的位置和大小输出了,没有重叠的啊,还是没法显示。。。使用groupbox也不行
熙风 2014-06-09
  • 打赏
  • 举报
回复
调试没有?确定循环了2次?

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧