Error inserting background image in a form of windows form

0

I wanted to know why I get this error when trying to put a background image in a form of windows form. I have seen like 3 tutorials where they put the same code and it does not give them error, I would really appreciate if someone could help me.

I do not want to put it directly in the properties of the form because I understand that there I can not tell the image that fits the size of the form.

    
asked by Ricardo Portillo 07.11.2018 в 16:29
source

2 answers

1

You could work this way:

// Metodo para convertir byte a Image
public Image DeByteImagen(string rutaImagen)
{      
      MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(rutaImagen));
      Image returnImage = Image.FromStream(memoryStream);
      return returnImage;
}

When loading the form (in the Load method)

this.BackgroundImage = DeByteImagen(Application.StartupPath + @"\img\Huellitas.jpg");
this.BackgroundImageLayout = ImageLayout.Stretch;
    
answered by 07.11.2018 / 17:07
source
1

You can do it quietly from the properties. First add the image in the property BackgroundImage and then adjust it with the property BackgroundImageLayout = Stretch for example. Greetings!

    
answered by 07.11.2018 в 16:50