【问题标题】:Create more than one type of arrays of PictureBox创建不止一种类型的 PictureBox 数组
【发布时间】:2020-01-07 05:18:08
【问题描述】:

我正在尝试创建多个 PictureBox 数组。
我唯一知道的是,我可以使用在代码中创建的有限数量的数组。

Dim CustomImage() As PictureBox = New PictureBox() {Array1, Array2,..and so on}

但我要解释的是如何创建这样的数组?
在本例中,用户输入数字 6,显示 6 个图片框。

Dim ArrayNumber as Integer = 6

Dim CustomImage() As PictureBox = New PictureBox() {some code that creates 6 arrays}

【问题讨论】:

  • "Array1" 是一个非常奇怪的图片框控件名称。此代码可以正常工作的几率很低,您必须传递已初始化的变量。在 Sub New 中,InitializeComponent() 调用之后是最早的。
  • 我该怎么做,我现在很困惑?
  • @MohamedHussain 你是说Array1Array2等等都是PictureBoxes数组,所以你想要一个PictureBoxes数组数组?
  • 您要存储图像还是图片框控件?

标签: arrays vb.net


【解决方案1】:

只是样本:

Dim myPictBox As PictureBox()
Private Const maxPBCount = 10

Private Sub CreateSomePictureBox(ByVal Count As Int16)
    If Count > maxPBCount Then
        Exit Sub
    End If
    Dim myPictBoxLength As Integer = 0
    If myPictBox Is Nothing = False Then
        myPictBoxLength = myPictBox.Length
    End If

    Do While myPictBoxLength > Count
        myPictBox(myPictBoxLength - 1).Dispose()
        myPictBoxLength -= 1
    Loop
    If Count <= 0 Then
        myPictBox = Nothing
        Exit Sub
    End If
    ReDim Preserve myPictBox(Count - 1)
    'Arrange Position of PictureBox
    MsgBox(myPictBoxLength)
    Do While myPictBoxLength < Count
        myPictBox(myPictBoxLength) = New PictureBox
        myPictBox(myPictBoxLength).Height = 30 
        myPictBox(myPictBoxLength).Width = 30
        myPictBox(myPictBoxLength).Location = New Point(35 * myPictBoxLength, 30)
        Me.Controls.Add(myPictBox(myPictBoxLength))
        myPictBox(myPictBoxLength).BackColor = Color.Red
        myPictBox(myPictBoxLength).Show()
        myPictBoxLength += 1
    Loop
    'Create Sub Procedure to Arrange The Picture Box Created 
    'ArrangePB()
End Sub

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
    CreateSomePictureBox(6)
End Sub

【讨论】:

  • myPictBoxLength = myPictBox.Length Length 属性是 Integer 而不是 Int16。
  • 什么是ArrangePB()
  • Size 不是 .Location
  • ArrangePB 是将图片框放置到容器的子程序,可能是我忘记复制了,上面的示例不需要,因为在创建时已分配。 MyPictBoxLength 将更改为整数。位置分配,我忘记改了,不好意思……
猜你喜欢
  • 2022-06-15
  • 1970-01-01
  • 1970-01-01
  • 2017-05-26
  • 2020-01-29
  • 1970-01-01
  • 2015-04-08
  • 1970-01-01
  • 2018-04-12
相关资源
最近更新 更多