我现在做了一个winCE下边的程序 想动态创建控件
于是 我写了下边的一段代码
PictureBox pic = new PictureBox();
Label lbName = new Label();
plCatagory.Controls.Add(pic);
lbName.Location = new Point(30, 15);
lbName.TextAlign = ContentAlignment.TopCenter;
lbName.BackColor = Color.Transparent;
lbName.Size = new Size(50, 15);
lbName.Text = catalog[j];
pic.Controls.Add(lbName);
pic.Tag = catalogValue[j];
pic.Location = new Point(x, y);
pic.Size = new Size(150, 60);
pic.Image = ILBackImage.Images[0];
pic.SizeMode = PictureBoxSizeMode.StretchImage;
pic.Click += new System.EventHandler(this.picBoxClick);
y = y + 60;
当执行到 pic.Controls.Add(lbName);
这句的时候 回报这个错 Value does not fall within the expected range. 是怎么回事
于是 我写了下边的一段代码
PictureBox pic = new PictureBox();
Label lbName = new Label();
plCatagory.Controls.Add(pic);
lbName.Location = new Point(30, 15);
lbName.TextAlign = ContentAlignment.TopCenter;
lbName.BackColor = Color.Transparent;
lbName.Size = new Size(50, 15);
lbName.Text = catalog[j];
pic.Controls.Add(lbName);
pic.Tag = catalogValue[j];
pic.Location = new Point(x, y);
pic.Size = new Size(150, 60);
pic.Image = ILBackImage.Images[0];
pic.SizeMode = PictureBoxSizeMode.StretchImage;
pic.Click += new System.EventHandler(this.picBoxClick);
y = y + 60;
当执行到 pic.Controls.Add(lbName);
这句的时候 回报这个错 Value does not fall within the expected range. 是怎么回事
this.Controls.Add(lbName);
如果要实现带说明的图片,最好加UserControl,把图片和label放在一个用户控件中。