Vb6 在Visual Basic 6.0中:创建动态控件数组

Vb6 在Visual Basic 6.0中:创建动态控件数组,vb6,Vb6,我想在我的表单上复制一个控件, 具有用户控件,该控件的名称与添加的“new”相同。 (Label1-->newLabel1) 这是我的代码片段: Private Sub CreateLabel(ByRef lblControl As Control) 'lblControl - this is the control i would like to duplicate 'The reference to the new created control itself so i

我想在我的表单上复制一个控件, 具有用户控件,该控件的名称与添加的“new”相同。 (Label1-->newLabel1)

这是我的代码片段:

Private Sub CreateLabel(ByRef lblControl As Control)

    'lblControl - this is the control i would like to duplicate


    'The reference to the new created control itself so i can work with it within this sub.
    Dim newControl As Control


    Set newControl = Form1.Controls.Add _
    ("Project.Project1", "new" & lblControl.Name, lblControl.Container)

    newControl.Visible = True

End Sub
如果我想复制一个未编入索引的控件,它将非常有效 然而,我在将数组中的控件复制为lblControl时遇到了问题。Name只是取其名称,而不是索引,用索引名称(lblControl.Name&“(“lblControl.index&”)替换名称实际上不起作用

此外,创建控件并在创建后更改其索引值也不起作用


因此,我的问题是,如何使用上述方法创建数组?

如果控件已经是控件数组,则使用
Load
创建控件的新实例

假设您有一个标签
lblControl
,其
索引在设计时设置为0(使其成为控件数组),您将使用以下代码添加它的另一个实例

Dim newControl As Control
Load lblLabelInControlArray(1) '1 is the Index value that will be sued
Set newControl = lblLabelInControlArray(1)
显然,您需要跟踪所使用的索引,因为VB6允许存在间隙,所以在加载和卸载它们时可能会产生混淆