for (int i = 0; i < FlowLayoutPanel1.Controls.Count; i++) { Panel pan = new Panel(); pan = (Panel)FlowPanel_Station.Controls[i]; string[] str = new string[8]; str[0] = "站点名称:"; str[1] = "连接状态:"; str[2] = "监听端口:"; str[3] = "更新时间:"; str[4] = ""; str[5] = ""; str[6] = ""; str[7] = ""; Label[] label = new Label[8]; Point[] point = new Point[8]; for (int k = 0; k < 8; k++) { if (k < 4) { label[k] = new Label(); label[k].Text = str[k]; label[k].Width = 70; pan.Controls.Add(label[k]); int x = pan.Location.X + 5; int y = pan.Location.Y + label[k].Height * k + 10; point[k] = new Point(x, y); label[k].Location = point[k]; } else { label[k] = new Label(); label[k].Text = str[k]; label[k].Width = 70; pan.Controls.Add(label[k]); int x = pan.Location.X + label[k - 4].Width + 5; int y = pan.Location.Y + label[k - 4].Height * (k - 4) + 10; point[k] = new Point(x, y); label[k].Location = point[k]; } } }
问题描述:
在FlowLayoutPanel控件中动态添加了多个Panel控件,然后循环分别在panel控件中添加Lable,不知道为什么调试结果只有第一个Panel显示label内容。后面的均不显示。
啥问题啊???
因为你给lable定位的时候超出了panel的可见范围,可以把label[k].Location = point[k];注释掉看看:)
我很好奇一下代码,解释下:
for (int i = 0; i < FlowLayoutPanel1.Controls.Count; i++) { Panel pan = new Panel(); pan = (Panel)FlowPanel_Station.Controls[i]; ...
红色的代码,你这是啥意思?
楼上正解!!!应该是不小心