我的表格上有4个图片框。我希望我的程序检查图片是否包含字符串标记,如果它不包含字符串Tag,则将图片放在该框中。我运行程序但没有任何反应没有错误。它根本不加载我的图片。我最好的猜测是我的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
答案 0 :(得分:0)
您正在使用" nextPB"这是检查没有图像。你的" nextTag"但是,变量检查没有Tag。将其更改为:
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