vb6 – 在Visual Basic 6.0中:创建动态控件数组
发布时间:2020-12-17 07:10:46 所属栏目:百科 来源:网络整理
导读:我想在我的表单上复制一个控件, 使用用户控件,该控件具有相同的名称并添加了“新”. (Label1 —- newLabel1) 这是我的代码片段: Private Sub CreateLabel(ByRef lblControl As Control) 'lblControl - this is the control i would like to duplicate 'The
我想在我的表单上复制一个控件,
使用用户控件,该控件具有相同的名称并添加了“新”. (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 如果我想要复制未编制索引的控件,它的效果很好 此外,创建控件并在创建后更改其索引值不起作用. 所以我的问题是,如何使用上述方法创建数组? 解决方法
如果控件已经是控件数组,则使用Load来创建控件的新实例.
假设您在设计时将索引设置为0(使其成为控件数组)时有一个标签lblControl,您将使用以下代码添加它的另一个实例. Dim newControl As Control Load lblLabelInControlArray(1) '1 is the Index value that will be sued Set newControl = lblLabelInControlArray(1) 显然你会想要跟踪你使用的索引,因为VB6确实允许间隙,所以当你加载和卸载它们时会让人感到困惑. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |