1

Im trying to make my picture change when a button is clicked so that the player can see the character attack. When they do so, so the picture should change to the attack image when the button is clicked and then back to the old image when the opponents turn starts.

All the images are saved in a folder named "images" inside the project folder, which is inside the "WindowsFormsApplication1" folder, but it says it cant find namespace images inside windowsformsapplication1

Here is the code I am using to change the image:

private void ArBut_Click(object sender, EventArgs e)
        {
            if (playerturn == true)
            {
                Ar.Image = global::WindowsFormsApplication1.images.archeratack.jpeg;
                drhp = drhp - 15;
                DrHP.Text = drhp.ToString();
                checkend();
                playerturn = false;
                dratak();
            }
        }
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
stev0104
  • 45
  • 1
  • 3
  • 11
  • You probably want to make those images 'Resources'..? [See here](http://stackoverflow.com/questions/1192054/load-image-from-resources-area-of-project-in-c-sharp) or [here](http://stackoverflow.com/questions/13592150/load-image-from-resources) – TaW Dec 13 '14 at 01:43

2 Answers2

1

You can't just set the image like that. First of all, because thats not a String, it thinks you are trying to access a code element. Obviously images is not a namespace or class within your code, so you get the compiler error.

You need to use PictureBox.Load (MSDN)

Ar.Load(@"./images/archeratack.jpeg");
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • i tried using Ar.Load(@"./images/archeratack.jpeg"); but it says that it cant find it. i saved the images folder in side bin/debug/, i apologize for my ignorance, im still learning how to program. – stev0104 Dec 13 '14 at 02:00
  • @stev0104 Thats a different problem. Obviously you need to make sure that the image exists at that path. Not really sure what else I can advise. – BradleyDotNET Dec 13 '14 at 02:02
  • i got it you where right the path was wrong it should have been .jpg not jpeg :) thanks for your help – stev0104 Dec 13 '14 at 02:05
0

You could try to create an Image object and use Image.FromFile("url")