gpt4 book ai didi

c# - 单击按钮后如何将一张图片更改为另一张图片

转载 作者:行者123 更新时间:2023-11-30 20:42:07 25 4
gpt4 key购买 nike

我有 2 张图片,使用 else-if 方法,我该如何做到当我点击图片 A 时,它变成图片 B,如果是图片 B,则返回图片A?这是我的代码:

private void Smalltubbutton1_Click(object sender, EventArgs e)
{
if(System.Drawing.Bitmap bitmap1 =
WindowsFormsApplication21.Properties.Resources.smalltub)
{
System.Drawing.Bitmap bitmap1 =
WindowsFormsApplication21.Properties.Resources.GRAYSCALEsmalltub;
}
else
{
System.Drawing.Bitmap bitmap1 =
WindowsFormsApplication21.Properties.Resources.smalltub
}
}

最佳答案

您可以使用 PictureBox 并使用适当的图像更改图像属性,并在每次单击时更改 bool 属性或变量。

private void pictureBox1_Click(object sender, EventArgs e)
{
if (flag)
pictureBox1.Image = WindowsFormsApplication21.Properties.Resources.GRAYSCALEsmalltub;
else
pictureBox1.Image = WindowsFormsApplication21.Properties.Resources.smalltub;
flag=!flag;
}

我希望这能解决您的问题。祝你好运。

关于c# - 单击按钮后如何将一张图片更改为另一张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com