我的收藏品不会通过我的所有物品

时间:2014-12-21 20:36:28

标签: vb.net visual-studio-2010

我在vb2010的编程类中正在开发一个最终项目,我创建的集合只通过For Each... Next中的一个对象。我已经包含了将对象添加到集合和我的For Each循环的代码。注意:我添加到集合中的代码可能比它需要的要复杂一些,但我们的想法是灵活选择将多少个对象添加到集合中。

Private Sub basicCountCollect(ByVal basicCount As Short)
    Dim name As String = ""
    Dim PB As New PictureBox
    For ShipCount As Short = 1 To basicCount
        name = "basicShip" & ShipCount
        PB.Name = name
        basicShipCount.Add(PB)
    Next
End Sub

Private Sub BasicShipPictureBox(ByVal XPic As Short)
    'Display basic ship picture boxes
    For Each ship As PictureBox In basicShipCount
        ship.Location = New Point(XPic, 100) 'Location of the ship
        ship.Size = New Size(200, 200) 'Size of the ship
        ship.Image = System.Drawing.Bitmap.FromFile( _ 
            My.Application.Info.DirectoryPath & "\basicShipImage.png") 'Load picture of the ship
        Me.Controls.Add(ship)
        XPic = XPic + 100
        MessageBox.Show(ship.Name) 'For debugging
    Next ship 
End Sub

0 个答案:

没有答案