【发布时间】:2019-12-23 00:42:34
【问题描述】:
我正在尝试检查 PictureBox 是否包含某个图像,我尝试这样做的方式似乎可以在我的脑海中起作用,但是,没有,我不确定是否有任何其他方法可以检查如果表单上的图片框包含某个图像。
private void user_btn_Click(object sender, EventArgs e)
{
//If statement to check if the forms picture box contains a certain image
if (pictureBox1.Image == Resources.user_male_white_red_brown)
{
this.Hide();
UserProfile User = new UserProfile();
User.ShowDialog();
User.pictureBox1.Image = Resources.user_male_white_red_brown;
this.Close();
}
else if (pictureBox1.Image == Resources.user_female_olive_orange)
{
this.Hide();
UserProfile User = new UserProfile();
User.ShowDialog();
User.pictureBox1.Image = Resources.user_female_olive_orange;
this.Close();
}
}
【问题讨论】:
-
图像(图片)是一个对象,而资源是一个工厂,它每次都会创建一个新图像,因此它永远不会匹配任何图片框中的图像。使用变量来跟踪显示的图像
标签: c# winforms picturebox