2013-11-26 231 views
3

我開發了一個使用Visual Studio IDE的Visual C#窗體表單應用程序。檢查圖片框值是否爲空

我的問題是如何檢查用戶是否選擇了圖像。

我粗略地檢查圖像就像一個字符串,整數對象,但它不工作

if(myPictureBox.Image == NULL){ 
    //The Image is Null 
} 
+1

請嘗試特定 – manish

+0

您可以添加您的代碼嗎? – Dan

+0

我已經編輯社區準則下的這個問題。請upvote釋放我。我被禁止問問題 – nifCody

回答

5

你可以做一個檢查這樣

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

或者你可以創建自己的擴展方法

public static bool IsNullOrEmpty(this PictureBox pb) 
{ 
    return pb == null || pb.Image == null; 
} 
+0

嗨大衛皮爾金頓, 我改變了你的代碼的一些變化,它的'知道工作 bool isNullOrEmpty =(myPictureBox.Image == null); – nifCody

+0

任何方式感謝您的幫助 – nifCody

+0

@NifrasIsmail,只是檢查它是否爲空,如果它是空的 –