首页 > 解决方案 > 用按钮复制对象vb6

问题描述

项目结构和UserControl

在此处输入图像描述

Formularios = Form = Form1
Controles de Usuario = User Controls = uc1

所有UserControl代码:

Option Explicit

Public Property Get AddType() As String
   AddType = cmbAddExample.Text
End Property

Public Property Let AddType(ByVal Value As String)
   cmbAddExample.Text = Value
End Property

Public Property Get AddNumber() As String
   AddNumber = Text1.Text
End Property

Public Property Let AddNumber(ByVal Value As String)
   Text1.Text = Value
End Property

在此处输入图像描述

Button添加(Añadir)代码:

Option Explicit
Dim indice As Integer

Private Sub btnAñadir_Click()
   indice = indice + 1

   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

   Load Text1(indice)
   Set Text1(indice).Container = uc1(indice)
   Text1(indice).Visible = True
   Text1(indice).Top = Text1(indice - 1).Top

   uc1(indice).AddType = uc1(0).AddType
   uc1(indice).AddType = ""

   Picture1.Visible = True

   If indice = 3 Then
   Me.btnAñadir.Enabled = False
   End If
End Sub

在此处输入图像描述

在此处输入图像描述

黑圈是一个UserControl有一个TextBox和一个ComboBox里面。红圈是一个PictureBox

所以,问题是PictureBox当我按下按钮添加时,我需要从 uc1 复制值。但是当我按下按钮时,它会显示下一个错误:

在此处输入图像描述

在此处输入图像描述

Compilation Error: Method or data member not found.

在这一行:

在此处输入图像描述

uc1(index).AddType = uc1(0).AddType

那么,有什么好办法吗?

标签: buttoncomboboxvb6

解决方案


在您的帖子中,您说用黑色圈出的对象是一个 UserControl,而实际上它是一个名为uc1(0). 由于 PictureBox 没有 AddType 属性,您会收到错误消息。

用 UserControl 替换此 PictureBox 将解决该错误。


推荐阅读