c# winform如何取得一个区域的所有控件对象
我有一个pictureBox对象,然后在区域里会加入若干其他对象(如其他picturebox),想取得里面picturebox的名字(可能不止一个)怎么获取里面的pict...
我有一个pictureBox对象,然后在区域里会加入若干其他对象(如其他picturebox),想取得里面picturebox的名字(可能不止一个)
怎么获取里面的picturebox对象
注意:pictureBox不是容器,所以没有“子控件” 展开
怎么获取里面的picturebox对象
注意:pictureBox不是容器,所以没有“子控件” 展开
1个回答
展开全部
设pictureBox1为父控件 pictureBox2为子控件
//设置pictureBox1可以有子控件
this.pictureBox1.HasChildren = true;
//设置pictureBox1在窗体中的位置
this.pictureBox1.Location = new System.Drawing.Point(38, 67);
this.pictureBox1.Size = new System.Drawing.Size(236, 196);
//设置pictureBox2的父控件为pictureBox1
this.pictureBox2.Parent = this.pictureBox1;
//检索指定位置的子控件
//GetChildAtPoint获取制定位置的子控件
this.pictureBox2.Parent = this.pictureBox1;
PictureBox[] ps = new PictureBox[10];
int i = 0;
for (int x = 0; x < this.pictureBox1.Width; x++)
{
for (int y = 0; y < this.pictureBox1.Height; y++)
{
if(this.pictureBox1.GetChildAtPoint(new Point(x,y)) != null)
{
ps[i] = new PictureBox();
ps[i] = (PictureBoxthis.pictureBox1.GetChildAtPoint(new Point(x, y));
i++;
}
}
}
//设置pictureBox1可以有子控件
this.pictureBox1.HasChildren = true;
//设置pictureBox1在窗体中的位置
this.pictureBox1.Location = new System.Drawing.Point(38, 67);
this.pictureBox1.Size = new System.Drawing.Size(236, 196);
//设置pictureBox2的父控件为pictureBox1
this.pictureBox2.Parent = this.pictureBox1;
//检索指定位置的子控件
//GetChildAtPoint获取制定位置的子控件
this.pictureBox2.Parent = this.pictureBox1;
PictureBox[] ps = new PictureBox[10];
int i = 0;
for (int x = 0; x < this.pictureBox1.Width; x++)
{
for (int y = 0; y < this.pictureBox1.Height; y++)
{
if(this.pictureBox1.GetChildAtPoint(new Point(x,y)) != null)
{
ps[i] = new PictureBox();
ps[i] = (PictureBoxthis.pictureBox1.GetChildAtPoint(new Point(x, y));
i++;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询