Visual Basic 6.0如何构建动态控件数组?

2026-05-06 13:111阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计420个文字,预计阅读时间需要2分钟。

Visual Basic 6.0如何构建动态控件数组?

我想要在我的表单上复制一个控件,使用用户控件,该控件具有相同的名称并添加了新前缀。(Label1 -> newLabel1)这是我的代码片段:Private Sub CreateLabel(ByRef lblControl As Control) ' lblControl=this

我想在我的表单上复制一个控件,
使用用户控件,该控件具有相同的名称并添加了“新”.
(Label1 —-> newLabel1)

这是我的代码片段:

Visual Basic 6.0如何构建动态控件数组?

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确实允许间隙,所以当你加载和卸载它们时会让人感到困惑.

本文共计420个文字,预计阅读时间需要2分钟。

Visual Basic 6.0如何构建动态控件数组?

我想要在我的表单上复制一个控件,使用用户控件,该控件具有相同的名称并添加了新前缀。(Label1 -> newLabel1)这是我的代码片段:Private Sub CreateLabel(ByRef lblControl As Control) ' lblControl=this

我想在我的表单上复制一个控件,
使用用户控件,该控件具有相同的名称并添加了“新”.
(Label1 —-> newLabel1)

这是我的代码片段:

Visual Basic 6.0如何构建动态控件数组?

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确实允许间隙,所以当你加载和卸载它们时会让人感到困惑.