Ignacio Gómez
Ignacio Gómez

Reputation: 1627

Set pictureBox's image property created on Run-time CF C#

I create a pictureBox on Run-time and then to access to it I use this code:

foreach(Control mycontrol in panel.Controls){
  if(control.Name == "picBox1"){
    //here I can work with my pictureBox
  }
}

But once I am inside the if sentence I can't put control.Image. Is there any property of Control which I could use to manage the picBox1's Image property?

SOLUTION As Rajesh suggested, casting the control solves the problem. I was trying to cast it by using (PictureBox)control.Image and it was wrong.

The right way of doing it is writting Rajesh's code: ((PictureBox)control).Image

Thanks for your help!

Upvotes: 1

Views: 608

Answers (1)

Rajesh Subramanian
Rajesh Subramanian

Reputation: 6490

use the following code

((PictureBox)Control).Image = /*image */

Hope this helps.

Upvotes: 3

Related Questions