检查是否在VB6中添加/删除对象 [英] Check with adding / removing objects in VB6

查看:72
本文介绍了检查是否在VB6中添加/删除对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a query, I have this interface:

ComboBox位于UserControl内,按下带有ComboBox的Add this UserControl按钮可将UserControl / ComboBox添加到PictureBox中:

The ComboBox are inside a UserControl, pressing the Add this UserControl button with the ComboBox adds the UserControl / ComboBox in a PictureBox:

我想要的是,例如,当用户选择两个ComboBox的值并按下按钮时,将这些选择的值添加转到PictureBox(下面),并清理UserControl中选择的值。我留下一幅图片,假设用户选择了组合的值:

What I want is that, for example, when the user selects values ​​of the two ComboBox and press the button add these selected values ​​go to the PictureBox (below) and the values ​​that are selected in the UserControl are cleaned.I leave a picture of what I say, suppose the user selected the values ​​of the combos:

选择了它们之后,添加这些按钮已启用,它们将在下面传递,而上面的将被清除:

Once you have selected them, the add these button is enabled, they pass below and those above are cleaned:

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

But, if I press the remove button you must remove the last loaded object and move to the top. I leave a descriptive image, press the remove button:

底部消失并上升:

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

Currently this is the code I use to add:

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

那么,有谁知道我该怎么做?还是可以,

So, does anyone have any idea how I can do what I am looking for? Or yes, is it possible?

按钮删除:

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


推荐答案

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

Using this answer as the starting point, you can implement these requirements fairly easily. I have copied relevant code from the other answer and modified it:

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

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

I have only coded for one control to illustrate the concept. You can add other controls as needed.

这篇关于检查是否在VB6中添加/删除对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆