开发者

using image in if statement

how can i use image in if statement?

for example i want to check in click event of a picturebox that if a specific image(for example image1) is in it,then do some work.thanks in advance

update:

like this the picturebox can be null or have an image in it,i want to check image1 is in it or not

    private void pictureBox34_Click(object sender, EventArgs e)
    {
        if (///picturebox34=image1)
        {
            f();
        }
    }

now when i compile this code i开发者_开发百科 took error:cannot convert system.drawing.image to bool


If you have all the images loaded into memory then you could simply perform a reference comparison between the Image object assigned to the PictureBox and the other Image objects to determine which one is in the PictureBox.

Alternatively when you assign the Image to the PictureBox you can set the Tag property of the PictureBox to identify the Image and use the value of the Tag property for the test in your event handler. Of course in this case you only need the one Image in memory, but you will have to have some kind of identifying information, like the name of the image to assign to the Tag property.

Update: Based on your updated question, it seems you are happy to perform a refernce comparison. Which you can do as follows

private void pictureBox34_Click(object sender, EventArgs e) 
{ 
    if (picturebox34.Image == image1) 
    { 
        f(); 
    } 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜