Displaying images from a picturebox list

扶醉桌前 提交于 2019-12-24 22:09:09

问题


I am trying to display a line of pictures in my program. But I am having a problem, where it is only showing the first image in the imagelist and only showing one image-box.

Private Cards As New List(Of PictureBox)
  Private Sub SetupCards()

    For i As Integer = 0 To imglist1.Images.Count - 1
        Dim PicCard As PictureBox = New PictureBox()
        PicCard.Width = 100
        PicCard.Height = 200
        PicCard.Top = 50
        PicCard.Left = 50
        Me.Controls.Add(PicCard)
        PicCard.Image = imglist1.Images(i)
        Cards.Add(PicCard)
    Next i
  End Sub

回答1:


You're placing the picture boxes on top of each other, which is why you only see the last card. You've got to set a different Left property for every picture box you add.

The solution is rather simple. Just add the picture box's width to Left, multiplied by the current index i.

PicCard.Left = 50 + PicCard.Width * i



回答2:


Don't need to keep the imaging controls in your own list if you add them to a parent container control.

Use ListView or third-party controls, or use custom drawing code if you need to use ListBox (which wraps respective Windows control). See C# Can I display images in a list box?



来源:https://stackoverflow.com/questions/48681708/displaying-images-from-a-picturebox-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!