|
使用 WithEvents 关键字声明一个 CommandButton 类型的对象变量,允许您编程该控件的事件。对象变量被设置为由 Add 方法返回的引用。要试验该例,把它的代码粘贴到声明部分并且运行该工程。
Option Explicit
Private WithEvents btnObj As CommandButton
Private Sub btnObj_Click()
MsgBox "This is a dynamically added button."
End Sub
Private Sub Form_Load()
Set btnObj = Controls.Add("VB.CommandButton", "btnObj")
With btnObj
.Visible = True
.Width = 2000
.Caption = "Hello"
.Top = 1000
.Left = 1000
End With
End Sub
这个........好像只能载入一个控件,定义时还不能使用数组,请问怎么样才能“运行时决定载入的控件的个数”??谢谢~~ |
|