程序是检查图片框是否为空以及是否有标签。工作不正常
Procedure is checks if picturebox is empty and if it has tag. Not working properly
我的表格上有 4 个图片框。我希望我的程序检查图片是否不包含字符串标签,如果不包含字符串标签,则将图片放在该框上。我运行的程序没有任何反应也没有错误。它根本不会加载我的图片。我最好的猜测是我的 IF 条件错误。这是我的程序:
Private Sub btnAddImage_Click(sender As Object, e As EventArgs) Handles btnAddImage.Click
ofdBrowsePictures.Multiselect = False
ofdBrowsePictures.Title = "Select Image to Upload"
ofdBrowsePictures.Filter = "Image Files |*.jpg*"
If ofdBrowsePictures.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim PBs() As PictureBox = {picMainImage, picImage2, picImage3, picImage4}
Dim nextPB = PBs.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
Dim nextTag = PBs.Where(Function(x) IsNothing(x.Tag)).FirstOrDefault
If Not IsNothing(nextTag) Then
nextPB.ImageLocation = ofdBrowsePictures.FileName
End If
End If
End Sub
您正在使用 "nextPB",它正在检查没有图像。但是,您的 "nextTag" 变量正在检查没有标记。将其更改为:
Private Sub btnAddImage_Click(sender As Object, e As EventArgs) Handles btnAddImage.Click
ofdBrowsePictures.Multiselect = False
ofdBrowsePictures.Title = "Select Image to Upload"
ofdBrowsePictures.Filter = "Image Files |*.jpg*"
If ofdBrowsePictures.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim PBs() As PictureBox = {picMainImage, picImage2, picImage3, picImage4}
Dim nextTag = PBs.Where(Function(x) IsNothing(x.Tag)).FirstOrDefault
If Not IsNothing(nextTag) Then
nextTag.ImageLocation = ofdBrowsePictures.FileName
End If
End If
End Sub
我的表格上有 4 个图片框。我希望我的程序检查图片是否不包含字符串标签,如果不包含字符串标签,则将图片放在该框上。我运行的程序没有任何反应也没有错误。它根本不会加载我的图片。我最好的猜测是我的 IF 条件错误。这是我的程序:
Private Sub btnAddImage_Click(sender As Object, e As EventArgs) Handles btnAddImage.Click
ofdBrowsePictures.Multiselect = False
ofdBrowsePictures.Title = "Select Image to Upload"
ofdBrowsePictures.Filter = "Image Files |*.jpg*"
If ofdBrowsePictures.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim PBs() As PictureBox = {picMainImage, picImage2, picImage3, picImage4}
Dim nextPB = PBs.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
Dim nextTag = PBs.Where(Function(x) IsNothing(x.Tag)).FirstOrDefault
If Not IsNothing(nextTag) Then
nextPB.ImageLocation = ofdBrowsePictures.FileName
End If
End If
End Sub
您正在使用 "nextPB",它正在检查没有图像。但是,您的 "nextTag" 变量正在检查没有标记。将其更改为:
Private Sub btnAddImage_Click(sender As Object, e As EventArgs) Handles btnAddImage.Click
ofdBrowsePictures.Multiselect = False
ofdBrowsePictures.Title = "Select Image to Upload"
ofdBrowsePictures.Filter = "Image Files |*.jpg*"
If ofdBrowsePictures.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim PBs() As PictureBox = {picMainImage, picImage2, picImage3, picImage4}
Dim nextTag = PBs.Where(Function(x) IsNothing(x.Tag)).FirstOrDefault
If Not IsNothing(nextTag) Then
nextTag.ImageLocation = ofdBrowsePictures.FileName
End If
End If
End Sub