foreach(Control ctrl in this.controls)
{
    if(ctrl is Label)
    {
        ctrl.Image=……//这里ctrl没有Image属性,但label是有的,怎么办?
    }
}

解决方案 »

  1.   


    foreach(Control ctrl in this.controls)
    {
         Label lb=ctrl as Label;
        if(lb!=null)
        {
            lb.Image=//设置你需要的东西
        }
    }
      

  2.   

    foreach(Control ctrl in this.controls)
    {
        if(ctrl is Label)
        {
            ctrl.BackgroundImage = ……//这里ctrl没有Image属性,但label是有的,怎么办?
        }
    }
      

  3.   

    if(ctrl is Label)
        {
            Label l=ctrl as Label;
        }
      

  4.   

    foreach(Control ctrl in this.controls)
    {
        if(ctrl is Label)
        {
            (ctrl as Label).Image = …
        }
    }