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

我想在我的表单上复制一个控件,
使用用户控件,该控件具有相同的名称并添加了“新”.
(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来创建控件的新实例.

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

Dim newControl As Control
Load lblLabelInControlArray(1) '1 is the Index value that will be sued
Set newControl = lblLabelInControlArray(1)

显然你会想要跟踪你使用的索引,因为VB6确实允许间隙,所以当你加载和卸载它们时会让人感到困惑.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...