Question

So I have a picture box. I want to change the picture in the box when its clicked. I want to call the image from the references of the program. Here is what I understand of the code to use: Here is a cut up snippet of what I am trying to do:

namespace Control
{
     public partial class Form1 : Form
     {
         private void pictureBox1_Click(object sender, EventArgs e)
         {
            pictureBox.Image=Properties.Resources.mypic;
         }
     }
}

The problem is, while using winforms C#, Visual Studio is not recognizing the "Properties" part of that code. I have tried this.Properties, Form1.Properties, and Control.Properties.

I have also set the image properties in my resource list to embed as well.

Was it helpful?

Solution

Try

yourAppName.Properties.Resources.mypic;
  • yourAppName being your application namespace.

OTHER TIPS

It doesn't know where the Properties class lives.

In the IDE:

  1. Right-click on Properties
  2. Select 'Resolve'

This is easier (to me) than remembering what namespace different classes live in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top