vb动态添加和删除PictureBox控件

前端之家收集整理的这篇文章主要介绍了vb动态添加和删除PictureBox控件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Option Explicit
Private WithEvents NewPicture As PictureBox
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮

Private Sub Command1_Click() '这个按钮用来添加新控件
If NewPicture Is Nothing Then
Set NewPicture = Controls.Add("VB.PictureBox","picture",Form1)
'增加新的按钮cmdNew
NewPicture.Move 500,500
'确定新增按钮cmdNew的位置
NewPicture.Visible = True
'显示该按钮
End If
End Sub

Private Sub Command2_Click() '这个按钮用来删除新控件If NewPicture Is Nothing Then Exit SubElse Controls.Remove NewPicture Set NewPicture = Nothing End IfEnd SubPrivate Sub NewButton_click() MsgBox "你点击了新建的PictureBox",vbDefaultButton1,"Click"End Sub

原文链接:https://www.f2er.com/vb/261393.html

猜你在找的VB相关文章