有没有大佬知道,为什么这个if不能生效呢?
逻辑判断有误,if..else也不正确,具体看下面的说明。有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~
if(pictureBox1.Image==imageList1.Images[0]){//这里判断如果图片为1,则应该切换到图片2
pictureBox1.Image=imageList1.Images[1];
}
else pictureBox1.Image=imageList1.Images[0];//如果pictureBox1.Image不是图片1,才切换为图片1
这个不是if没有生效吧,而是由于你没有使用else条件,导致后面的 pictureBox1.Image = inmageList1.Images[1] 一直覆盖了if 里面的pictureBox1.Image = inmageList1.Images[0]
从图片里压根看不出来什么。你自己打个断点调试看看,这两个值是否相等
你这个不管前面的if有没有生效,运行pictureBox1.Image = inmageList1.Images[1]都会使得pictureBox1.Image 都会被赋值为inmageList1.Images[1],你应该在pictureBox1.Image = inmageList1.Images[1]前面加上else