请教VB高手一个删除控件的问题

来源:百度知道 编辑:UC知道 时间:2024/05/20 09:05:40
比如我在form1的picture1里建了很多动态控件,有image,picture,line等,怎么能实现点一下这个控件,然后按下delete键就能把它删除了呢?

Dim i As Integer

Private Sub Command1_Click()
For i = 1 To 4
Load Image1(i)
Image1(i).Visible = True
Image1(i).Left = Image1(i - 1).Left + 50
Next i
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete And i > 0 Then
Unload Image1(i)
End If

End Sub

Private Sub Form_Load()
Me.Picture1.ScaleMode = 3
Me.KeyPreview = True
End Sub

Private Sub Image1_Click(Index As Integer)
Image1(Index).Appearance = 0
i = Index
End Sub

好像只有从属性中先选中吧