gpt4 book ai didi

c# - 检查图片框值是否为空

转载 作者:行者123 更新时间:2023-11-30 13:57:40 26 4
gpt4 key购买 nike

我使用 Visual Studio IDE 开发了可视化 C# windows 窗体应用程序。

我的问题是如何检查用户是否选择了图像。

我粗略地检查了像字符串、整数对象这样的图像,但它不起作用

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

最佳答案

你可以这样检查

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

或者您可以创建自己的扩展方法

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

关于c# - 检查图片框值是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20209446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com