因此,我正在尝试创建一个简单的程序,只需在单击时更改图片框中的图片即可.我目前只使用两张图片,所以我的图片框点击事件功能的代码如下所示:
private void pictureBox1_Click(object sender, EventArgs e)
{
if (pictureBox1.Image == Labirint.Properties.Resources.first)
pictureBox1.Image = Labirint.Properties.Resources.reitmi;
else if (pictureBox1.Image == Labirint.Properties.Resources.reitmi)
pictureBox1.Image = Labirint.Properties.Resources.first;
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因if语句不起作用,图片不会改变.我该怎么办?
注:原代码包含与第二个bug if第一的毁灭效果,如果条件将与修复所建议的工作Cyral的答案,但增加else并没有解决这个问题-通过代码步进else仍然显示没有匹配的任何图像.
if (pictureBox1.Image == Labirint.Properties.Resources.first)
pictureBox1.Image = Labirint.Properties.Resources.reitmi;
if (pictureBox1.Image == Labirint.Properties.Resources.reitmi) // was missing else
pictureBox1.Image = Labirint.Properties.Resources.first;
Run Code Online (Sandbox Code Playgroud) 我想更改 std::map (它是哈希函数),以便在迭代时以插入的方式返回对。我尝试过使用无序地图,但没有成功。所以我想我必须创建一个哈希函数,该函数每次都会递增并返回更大的值。我怎样才能做到这一点?我不使用大数据,所以性能不是问题。