stev0104
stev0104

Reputation: 45

trying to change a picture box c#

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();
            }
        }

Upvotes: 1

Views: 44

Answers (2)

Erik Remkus
Erik Remkus

Reputation: 37

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

Upvotes: 0

BradleyDotNET
BradleyDotNET

Reputation: 61349

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");

Upvotes: 1

Related Questions