Check with adding / removing objects in VB6

萝らか妹 提交于 2020-02-25 04:19:27

问题


I have a query, I have this interface:

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

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:

The bottom disappears and goes up:

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?

Button Remove:

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

回答1:


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.



来源:https://stackoverflow.com/questions/59665051/check-with-adding-removing-objects-in-vb6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!