button - 检查在 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
解决方案
使用这个答案作为起点,您可以相当容易地实现这些要求。我从另一个答案中复制了相关代码并对其进行了修改:
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
我只编写了一个控件来说明这个概念。您可以根据需要添加其他控件。
推荐阅读
- r - 乘以 R 增加的百分比
- python - pd.read_html 读取一个空表
- amazon-ec2 - Amazon aws route53,将子域重定向到在特定端口下运行的 ec2 应用程序
- c# - 如何检查子模型状态是否有效,而不是检查 asp.net 核心中的主模型状态?
- android - Android片段ClassNotFoundException:找不到类android.support.constraint.ConstraintLayout
- tcl - 如何在 TCL 脚本中将字符串从说英语翻译成日语
- c# - 方法“ImageAnnotatorClient.Create”没有重载需要 1 个参数
- android - Android Java 与 Native C 未定义的对 `__android_log_print' 的引用
- javascript - TypeError:Webpack 导入的模块不是函数
- python - 熊猫同时在数据框的两列上滚动应用功能