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");
            }

Recommended Answers

All 2 Replies

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

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.