我有一个查询,我有这个界面:
ComboBox位于UserControl内,按ComboBox的Add this UserControl按钮可将UserControl / ComboBox添加到PictureBox中:
我想要的是,例如,当用户选择两个ComboBox的值并按下按钮时,将这些选择的值添加到PictureBox(下面)中,然后将其添加到PictureBox中。清理UserControl。我留下我说的话,假设用户选择了组合的值:
选择它们后,“添加这些”按钮将被启用,它们将在下面传递,而上面的将被清除:
但是,如果我按下“删除”按钮,则必须删除最后一个加载的对象并移至顶部。我留下一个描述性图片,请按“删除”按钮:
底部消失并上升:
当前,这是我用来添加的代码:
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
答案 0 :(得分:1)
使用this answer作为起点,您可以轻松实现这些要求。我已经从其他答案中复制了相关代码并对其进行了修改:
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
我只编写了一个控件的代码来说明这个概念。您可以根据需要添加其他控件。