2

How can I set a picture to a PictureBox in code?

The code below gives me the error:

Cannot implicitly convert Bitmap to String.

    private void ptbLocalidadAdd_MouseEnter(object sender, EventArgs e)
    {
        ptbLocalidadAdd.ImageLocation = Properties.Resources.addg;
    }
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

3

If the resource is a bitmap, this should work:

ptbLocalidadAdd.Image = Properties.Resources.addg;
Ani
  • 111,048
  • 26
  • 262
  • 307
  • What if the bitmap is created during the life of the application? How do we save it as a resource? – Gaʀʀʏ Mar 06 '13 at 05:32
  • @Garreh: if you have the memorystream of the bitmap in memory then convert it to a bitmap object and assign that as the `Image` instead of the `Properties.Resources.addg`. I think saving the dynamically created image to the resources seems like a bit of overkill unless you will use it when the program runs for a second time or any subsequent times. – Mike_OBrien May 01 '13 at 16:48