试图更改图片框c#

时间:2014-12-13 01:32:52

标签: c# image button

我试图在点击按钮时更改我的照片,以便玩家可以看到角色攻击。当他们这样做时,图片应该在点击按钮时变为攻击图像,然后在对手开始时返回旧图像。

所有图像都保存在项目文件夹中名为“images”的文件夹中,该文件夹位于“WindowsFormsApplication1”文件夹中,但它说它无法在windowsformsapplication1中找到命名空间图像

以下是我用来更改图片的代码:

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

2 个答案:

答案 0 :(得分:1)

你不能像这样设置图像。首先,因为那不是String,它认为您正在尝试访问代码元素。显然images不是代码中的命名空间或类,因此会出现编译错误。

您需要使用PictureBox.LoadMSDN

Ar.Load(@"./images/archeratack.jpeg");

答案 1 :(得分:0)

你可以尝试创建一个Image对象并使用Image.FromFile(" url")