Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check the Picture box value is null or not

Tags:

c#

winforms

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
}
like image 830
nifCody Avatar asked Nov 26 '13 05:11

nifCody


1 Answers

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;
}
like image 66
David Pilkington Avatar answered Sep 18 '22 20:09

David Pilkington