首页 > 解决方案 > 检查在 VB6 中添加/删除对象

问题描述

我有一个查询,我有这个界面:

在此处输入图像描述

ComboBox 位于 UserControl 内,使用 ComboBox 按 Add this UserControl 按钮可在 PictureBox 中添加 UserControl / ComboBox:

在此处输入图像描述

我想要的是,例如,当用户选择两个 ComboBox 的值并按下按钮时,将这些选择的值添加到 PictureBox(下),并清除 UserControl 中选择的值.我留下一张我说的话,假设用户选择了combo的值:

在此处输入图像描述

一旦你选择了它们,添加这些按钮就会被启用,它们会在下面传递,上面的会被清除:

在此处输入图像描述

但是,如果我按下删除按钮,您必须删除最后加载的对象并移动到顶部。我留下一个描述性的图像,按删除按钮:

在此处输入图像描述

底部消失并上升:

在此处输入图像描述

目前这是我用来添加的代码:

Option Explicit
Dim indice As Integer

Public Property Let AddType(ByVal Value As String)
   cmbAddExample.Text = Value
End Property

Private Sub btnAñadir_Click()
   indice = indice + 1

   Picture1.Visible = True

   Load uc1(indice)
   Set uc1(indice).Container = Picture1
   uc1(indice).Visible = True
   uc1(indice).Top = IIf(indice = 1, 0, uc1(indice - 1).Top + uc1(indice - 1).Height + 20)

   Load cmbAddExample(indice)
   Set cmbAddExample(indice).Container = uc1(indice)
   cmbAddExample(indice).Visible = True
   cmbAddExample(indice).Top = cmbAddExample(indice - 1).Top
   CargaIDTipoNumero

   uc1(indice).AddType = uc1(0).AddType
   uc1(indice).AddType = ""


   If indice = 3 Then
   Me.btnAñadir.Enabled = False
   End If
End Sub

那么,有没有人知道我该如何做我正在寻找的东西?或者是的,有可能吗?

按钮移除:

Private Sub btnQuitar_Click()
   indice = cmbAddExample().Count - 1
   If indice > 0 Then
       Unload cmbAddExample(indice)
       End If
End Sub

标签: buttoncomboboxvb6controls

解决方案


使用这个答案作为起点,您可以相当容易地实现这些要求。我从另一个答案中复制了相关代码并对其进行了修改:

Private Sub btnAdd_Click()
   index = index + 1

   Load uc1(index)
   Set uc1(index).Container = Picture1
   uc1(index).Visible = True
   uc1(index).Top = IIf(index = 1, 0, uc1(index - 1).Top + uc1(index - 1).Height + 20)

   'copy the information down
   uc1(index).AddType = uc1(0).AddType
   uc1(0).AddType = ""

   Picture1.Visible = True
End Sub

Private Sub btnRemove_Click()
   If index = 0 Then Exit Sub

   'copy the information back up and remove the control
   uc1(0).AddType = uc1(index).AddType
   Unload uc1(index)

   index = index - 1
   If index = 0 Then Picture1.Visible = False
End Sub

我只编写了一个控件来说明这个概念。您可以根据需要添加其他控件。


推荐阅读