Search code examples
c#winformspicturebox

Setting the image of an ImageBox in a UserControl - c#


I'm trying to set the image of a PictureBox on a FlowControl, however I can only access the background image property.

 if (File.Exists(filePath))
 {
      flowProd.Controls["picture_product"].BackgroundImage = Image.FromFile(filePath);
 }

The .Image property isn't available to me. Does anyone know of a way for me to set the Image of my picture box?


Solution

  • The Controls in FlowControl is base type of control, you have to cast control to see all of properties. exmaple:

    ((PictureBox)flowProd.Controls["picture_product"]).Image = Image.FromFile(filePath);