【发布时间】:2016-03-17 08:18:31
【问题描述】:
我的图片框中有一个图像,使用资源我想要更改图像,当我单击 icon.png 时,它应该在图片框中更改为 icon1.png,然后当我再次单击图片框时,它应该改为icon.png
private void pictureBox10_Click(object sender, EventArgs e)
{
if (pictureBox10.ImageLocation != @"icon1.png")
{
var image = Image.FromFile(@"icon1.png");
pictureBox10.Image = image;
}
if (pictureBox10.ImageLocation == @"icon1.png")
{
var image = Image.FromFile(@"icon.png");
pictureBox10.Image = image;
}
}
但它不起作用,请帮我解决这个问题。
【问题讨论】:
-
你试过什么?发生什么了?你试过打电话给
DoEvents()吗? -
我只是使用 onlick 函数来更改图像,而 picurebox10.imagelocation 给出了一个空值,这就是为什么它只适用于第一个 if 条件
-
调试代码时,ImageLocation 属性中出现了什么?我不是 100% 确定设置 Image 属性也会设置 ImageLocation 属性
-
它有效,但仅适用于第一个 if 条件,其中 picturebox10.imagelocation 的值为 null,因此它满足第一个条件,因此仅适用于第一个条件图像正在更改
-
其实条件不行