image不是system.windows.forms.control的成员

时间:2014-08-18 11:47:58

标签: vb.net

我有10个名为imagebox1的imagebox,imagebox2 ..... imagebox10

当我点击一个按钮时,它会运行一个名为" load"它将图像列表中的图像加载到循环中的图像框中

Private Sub LOAD(ByVal task As String)
Dim j As Integer , ctl1 As Control
For j = 1 To 10
ctl1 = Controls(" PictureBox" & Format(j))   
ctl1.Image = imglistPics.Images(j) 'THİS LİNE GİVES THE ERROR(image is not a member of system.windows.forms.control)
ctl.visible = true   'THİS LİNE WORKS
next   
End Sub

我试过这个。但它给出了这个错误" System.NullReferenceException"。但是imagelist不是空的!

CType(ctl1, PictureBox).Image = imglistPics.Images(j)

1 个答案:

答案 0 :(得分:0)

你应该这样做

    Dim j As Integer, ctl1 As PictureBox
    For j = 1 To 10
        ctl1 = CType(Controls("PictureBox" & Format(j)), PictureBox)
        ctl1.Image = imglistPics.Images(j - 1) 'Note: image index starts from 0
        ctl1.Visible = True 
    Next