我想遍历页面中的picturebox  获得picturebox .x的最大值和最小值,
foreach (Control c in this.Controls) 

if (c.GetType() == typeof(PictureBox)) 

....................................//代码

}
求代码部分,谢谢!

解决方案 »

  1.   

       Single MinVal=800,MaxVal=0;
                foreach (Control c in this.Controls)  
                {  
                    if (c.GetType() == typeof(PictureBox))  
                        {
                            if (MinVal > c.Location.X)
                            {
                                MinVal = c.Location.X;
                            }
                            if (MaxVal < c.Location.X)
                            {
                                MaxVal = c.Location.X;
                            }
                        }  
                }
                MessageBox.Show(MinVal + "    " + MaxVal);
      

  2.   

    int min=0;
    int max=0;
    foreach (Control c in this.Controls)  
                {  
                    if (c.GetType() == typeof(PictureBox))  
                        {
                            if (MinVal > c.Location.X)
                            {
                                MinVal = c.Location.X;
                                continue;
                            }
                            if (MaxVal  < c.Location.X)
                            {
                                MaxVal = c.Location.X;
                                continue;
                            }
                        }  
                }
               MessageBox.Show(MinVal + "    " + MaxVal);