0

hi i am trying to make an if function to check the picturebox background but it is not working. i tried .equal or image.fromfile but nothing is working. can anyone help me pls?

if (pbxap.BackgroundImage.Equals("..\\..\\Images\\tbl9.jpg"))
            {
                //display error
                MessageBox.Show("No records found on this table");
            }
2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by domingo
0

Equals() method won't work for Image unless you are checking which object is it pointing to. A solution for your problem is:

Declare the error image as a class-level variable (i.e declare it above public Form1() {.....):

Image errorImage = Image.FromFile("..\\..\\Images\\tbl9.jpg");

Now when you are assigning the error image use that variable:

// Error! No records
pbxap.Image = errorImage;

To check if error image is assigned to picturebox's image, use:

if (pbxap.Image == errorImage)
{
   //display error
   MessageBox.Show("No records found on this table");
}

Hope that helps.

Thanks

0

thanks a lot for your reply but i have worked it out in a different way i compared the width and the height of the picturebox and image. Thanks :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.