如何检查PictureBox控件是否有图像 [英] How To Check PictureBox Control has image or not

查看:178
本文介绍了如何检查PictureBox控件是否有图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法查看图片框





I am having Trouble to check picture box


if (pictureBox1.Image != null)
{
    Common.MessageBoxUtilities.WarningMessageBox("You Have Image");
}
else if (pictureBox1.Image == null)
{
    Common.MessageBoxUtilities.WarningMessageBox("You Dont Have Image");
}





控制每次运行时都会转到if else语句,无论我选择了图像还是不。请帮我解决



control goes to if else statement every time i run it, whether i have image selected or not. please help me to solve

推荐答案

您的代码:

Your code:
if (pictureBox1.Image != null)
    {
    Common.MessageBoxUtilities.WarningMessageBox("You Have Image");
    }
else if (pictureBox1.Image == null)
    {
    Common.MessageBoxUtilities.WarningMessageBox("You Dont Have Image");
    }

(与此相同:

(which is the same as this:

if (pictureBox1.Image != null)
    {
    Common.MessageBoxUtilities.WarningMessageBox("You Have Image");
    }
else
    {
    Common.MessageBoxUtilities.WarningMessageBox("You Dont Have Image");
    }

但效率低,可读性差。)



如果它总是显示你没有图像,那就是因为你没有图像:Image属性是 null ,或为空。我们无法解决这个问题,因为您要么没有将图像设置到PictureBox中,要么已将其清除 - 我们无法访问您的硬盘或看到您的屏幕,所以我们不能说:看这里 - 就是这样。



所以,使用Visual Studio:在代码视图中右击单词 pictureBox1 ,并选择查找所有引用。这将显示代码中使用PictureBox的所有位置的列表。他们中的任何一个设置了Image属性吗?如果没有,那就是你的问题。如果他们这样做,他们设置了什么?设置断点并在运行代码时查看它。

but less efficient and less readable.)

If it always shows "You Dont Have Image", then that is because you don't have an image: the Image property is null, or empty. We can't fix that, because you either haven't set an image into the PictureBox, or you have cleared it out - we can't access your HDD or see your screen, so we can't say: "look here - it's that bit."

So, use Visual Studio: right click the word pictureBox1 in your code view, and select "Find all references". This will bring up a list of everywhere the PictureBox is used in your code. Do any of them set the Image property? If not, that's your problem. If they do, what do they set it with? Set a breakpoint and look at it when you run your code.


确保记住您使用的属性。

我正在设置BackgroundImage属性并访问图像财产,听起来很糟糕。
Make Sure To Remember the Property you use.
I was setting BackgroundImage Property and Accessing the Image Property, sounds awful though.


这篇关于如何检查PictureBox控件是否有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆