增加新按钮程序清单(增加新按钮
exe) 注意:本程序较难
'指出下面所使用的新变量必须先声明,这样会自动纠错 Option Explicit '通过使用 WithEvents 关键字声明一个对象变量为新的命令按钮 Private WithEvents NewButton As CommandButton Private Sub cmd_add_Click() If NewButton Is Nothing Then '增加新的按钮cmdNew Set NewButton = Controls
Add("vb
commandButton", "cmdnew", Me) NewButton
Move cmd_add
Left, cmd_add
Top - 580, cmd_add
Width NewButton
Caption = "新增的按钮" NewButton
Visible = True Else MsgBox "你已经增加了新的按钮
", 0, "提示框" End If End Sub Private Sub cmd_minus_Click() If NewButton Is Nothing Then MsgBox "你没有增加新按钮
", 0, "提示框" Else Controls
Remove NewButton Set NewButton = Nothing End If End Sub Private Sub cmd_test_Click() If NewButton Is Nothing Then MsgBox "你没有增加新的按钮
", 0, "提示框" Else NewButton
Caption = "测试成功
" End If End Sub '新增控件的单击事件 Private Sub NewBut