C#遍历控件

来源:互联网 发布:java面向对象什么意思 编辑:程序博客网 时间:2024/05/17 05:03
c# winform 循环遍历界面上的所有控件
C#代码

foreach (System.Windows.Forms.Control control in this.groupBox2.Controls)//遍历groupBox2上的所有控件   

    {   

    if (control is System.Windows.Forms.PictureBox)   

     {   

      System.Windows.Forms.PictureBox pb = (System.Windows.Forms.PictureBox)control;   

      pb.AllowDrop = true;   

     }   

    }  

--------------------------------------------------------------------------------------------------------------------------

C#代码

foreach (System.Windows.Forms.Control control in this.Controls)//遍历Form上的所有控件   

  {   

 if (control is System.Windows.Forms.PictureBox)   

  {   

   System.Windows.Forms.PictureBox pb = (System.Windows.Forms.PictureBox)control;    

    pb.AllowDrop = true;   

     }   

   }  

原创粉丝点击