使用按钮复制对象 vb6
Copy objects with a button 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
那么,有什么好处吗?
在您的 post 中,您说黑色圈出的对象是一个 UserControl,而实际上它是一个名为 uc1(0)
的 PictureBox。由于 PictureBox 没有 AddType 属性,您会收到错误消息。
用 UserControl 替换此 PictureBox 将解决错误。
项目结构和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
那么,有什么好处吗?
在您的 post 中,您说黑色圈出的对象是一个 UserControl,而实际上它是一个名为 uc1(0)
的 PictureBox。由于 PictureBox 没有 AddType 属性,您会收到错误消息。
用 UserControl 替换此 PictureBox 将解决错误。