vb动态添加和删除PictureBox控件

    技术2022-05-20  58

    Option ExplicitPrivate 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 IfEnd 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


    最新回复(0)