Hello guys. I made a picture box and i want like when a button is pressed , the BackgroundImage of Picture Box to be changed in a screenshot from my resources.

Look what i did:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem.Equals("Rocket Launcher I"))
                pictureBox1.BackgroundImage = "sa-mp-042.png";
        }

But i get error: Error2: Cannot implicitly convert type 'string' to 'System.Drawing.Image'

Recommended Answers

pictureBox1.BackgroundImage = Image.FromFile("sa-mp-042.png"); should work

Jump to Post

All 4 Replies

pictureBox1.BackgroundImage = Image.FromFile("sa-mp-042.png"); should work

Hello guys. I made a picture box and i want like when a button is pressed , the BackgroundImage of Picture Box to be changed in a screenshot from my resources.

Look what i did:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem.Equals("Rocket Launcher I"))
                {
pictureBox1.BackgroundImage = property.resources.abc.png;
                }
           else
             {
                   pictureBox1.BackgroundImage = property.resources.xyz.png;
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.