6

I have developed a visual C# windows form application using Visual Studio IDE.

My problem is how to check if the user has selected an image or not.

I roughly check the Image like a String, Integer objects but it does not work

if(myPictureBox.Image == NULL){
    //The Image is Null
}
3
  • 1
    please try being specific
    – manish
    Commented Nov 26, 2013 at 5:53
  • Can you add your code?
    – Dan
    Commented Nov 26, 2013 at 5:53
  • I have edit this question under community guideline. Please upvote to release me. I was banned to ask questions
    – nifCody
    Commented May 21, 2015 at 17:49

2 Answers 2

10

You can do a check like this

bool isNullOrEmpty = myPictureBox == null || myPictureBox.Image == null;

Or you can create your own extension method

public static bool IsNullOrEmpty(this PictureBox pb)
{
    return pb == null || pb.Image == null;
}
2
  • Hi David Pilkington, I change some changes in your code its' know work bool isNullOrEmpty = (myPictureBox.Image == null);
    – nifCody
    Commented Nov 26, 2013 at 7:18
  • @NifrasIsmail that just checks if it is empty not if it is null Commented Nov 26, 2013 at 7:27
0

Try this.

if(myPictureBox.ImageLocation == NULL){
//The Image is Null

}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.