繁体   English   中英

检查图片框是否为空

[英]Check if PictureBox is empty

我有一个简单的程序,用户需要在其中输入图像和其他信息,例如 Lname、Fname 等。然后我需要将保存的数据真正包含PictureBox中的Image

我在If语句中尝试过这个:

picturebox1.image = nothing

但当然它不会工作。 我不知道防止用户在没有图像的情况下保存数据的代码

If tbLName.Text = "" Or
   tbFName.Text = "" Or
   picturebox1.image = Nothing or
   cbCategory.SelectedIndex = -1 Then
    MessageBox.Show("Input data to Update", "Update", 
    MessageBoxButtons.OK, MessageBoxIcon.Error)
    Return            
End If

尝试

picturebox1.image Is Nothing 

首先不要将图片文件分配给PictureBox1 的BackgroundImage 属性,而是将图片图像分配给PictureBox1 的ImageLocation 属性。 您可以在设计时或运行时在属性窗口中设置它,您可以通过PictureBox1.ImageLocation = "Full image path\\images.png"进行分配。 现在您可以通过以下代码进行检查。 if PictureBox1.ImageLocation="" then No image else image exists end if

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM