【发布时间】:2012-01-19 23:14:49
【问题描述】:
我想在单击一次时更改按钮的 BackgroundImage,然后在再次单击时将其更改回原始图像(它会一遍又一遍地工作)。我的代码 sn-p 是这样的:
private void handButton_Click(object sender, EventArgs e)
{
if (handButton.BackgroundImage == WindowsFormsApplication1.Properties.Resources.Hands_Right)
{
handButton.BackgroundImage = WindowsFormsApplication1.Properties.Resources.Hands_Left;
}
else if (handButton.BackgroundImage == WindowsFormsApplication1.Properties.Resources.Hands_Left)
{
handButton.BackgroundImage = WindowsFormsApplication1.Properties.Resources.Hands_Right;
}
}
但是当我运行程序并单击按钮时;没发生什么事。图像是 32x32,我可以清楚地看到原始图像。单击时,原始图像将保留在那里。没有其他变量影响这个 sn-p(至少,搜索“handButton”只能从这个 sn-p 得到结果)。
有什么建议吗?我没有错误,所以我怀疑我做错了。有没有更好的方法来回更改图像?
【问题讨论】:
-
只是检查一下,点击事件处理了吗?单步执行代码时会发生什么?原始图像是什么?如果它不是左或右,它永远不会设置。
-
对不起,我不明白你的意思。我可以拉出一些窗口来显示执行的代码吗?