المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to modify the foreach identifier?



C# Programming
05-14-2009, 07:04 AM
I have several PictureBox Controls in my Form. I want to change the Image property of one of them depending on its Tag property. I have some code like this:


foreach(Control ctrl in this.controls)
{
if(ctrl.GetType().ToString() == "System.Windows.Form.PictureBox")
{
System.Windows.Form.PictureBox temPic = (System.Windows.Form.PictureBox)ctrl;
if(tempPic.Tag="1")
{
tempPic.Image = someImg //an image object
ctrl = tempPic;
}
}
}


Doing this I get a error:


Cannot assign to 'ctrl' because it is a 'foreach iteration variable'


Is there any workaround for this, or any ideas in order to achive this goal?

Any help would be apreciated http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif

Ivan