检查在 VB6 中添加/删除对象
Check with adding / removing objects in VB6
我有一个查询,我有这个界面:
ComboBox 在 UserControl 中,按下 Add this UserControl 按钮和 ComboBox 会在 PictureBox 中添加 UserControl / ComboBox:
我想要的是,例如,当用户选择两个ComboBox的值并按下按钮时,将这些选择的值添加到PictureBox(下图)和选择的值在UserControl中是cleaned.I留个图说什么,假设用户选择了combos的值:
一旦你选择了它们,添加这些按钮就被启用,它们从下面通过,上面的被清除:
但是,如果我按下删除按钮,您必须删除最后加载的对象并移动到顶部。我留下一张描述性图片,按删除按钮:
底部消失并上涨:
目前这是我用来添加的代码:
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
以 为起点,您可以相当轻松地实现这些要求。我从另一个答案中复制了相关代码并进行了修改:
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
我只编写了一个控件来说明这个概念。您可以根据需要添加其他控件。
我有一个查询,我有这个界面:
ComboBox 在 UserControl 中,按下 Add this UserControl 按钮和 ComboBox 会在 PictureBox 中添加 UserControl / ComboBox:
我想要的是,例如,当用户选择两个ComboBox的值并按下按钮时,将这些选择的值添加到PictureBox(下图)和选择的值在UserControl中是cleaned.I留个图说什么,假设用户选择了combos的值:
一旦你选择了它们,添加这些按钮就被启用,它们从下面通过,上面的被清除:
但是,如果我按下删除按钮,您必须删除最后加载的对象并移动到顶部。我留下一张描述性图片,按删除按钮:
底部消失并上涨:
目前这是我用来添加的代码:
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
以
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
我只编写了一个控件来说明这个概念。您可以根据需要添加其他控件。