0

我正在尝试创建一个属性数组。为了简化我的问题,我创建了一个迷你项目

项目:我有 3 个形状,当我按下按钮时会改变颜色和数字。我为每组属性创建了一个类。

Public Class Shape
  Dim _color As Color

End Class

添加几个对象进行测试(首先编码颜色)

 Public Shared Sub Main()

    Dim ShapeList As New List(Of Shape)
    ShapeList .Add(New Shape() With {_color = Color.Blue})
    ShapeList .Add(New Shape() With {_color = Color.Green})
    ShapeList .Add(New Shape() With {_color = Color.Red})

    Display()
  End Sub

当按下按钮时,我希望显示来自对象数组的排序/随机集

Public Sub Display(ByVal ShapeList As Object)

    Dim ScreenObject As Array
    ScreenObject(0) With {.OvalShape1}  'This is where I am stuck
    ScreenObject(1) =  .OvalShape2      'How to create this property in the
                                        'ScreenObject array?

        For Each obj As Shape In ShapeList
        ScreenObject(0).Color = ShapeList(0).Color
End Sub

澄清:这三个形状分别是 OvalShape1、2 和 3。但是对于我在VB中的一些小技能,我很难找到答案。

4

0 回答 0