動態新增大量控件時,怎麼指定它的事件?

rivensun 2003-08-21 05:29:25
如題

Private WithEvents Ctltmp As CommandButton
sub dd()
Set Ctltmp = Me.Controls.Add("Forms.CommandButton.1", "F2Btntmp1", True)
end sub

Private Sub Ctltmp_Click()
MsgBox "ctltmp"
End Sub

這樣可以動態新增一個CommandButton


如我要動態新增100個CommandButton

是不是一定要預先定義好一百個變量
象這樣
Private WithEvents Ctltmp1As CommandButton
.
.
.Private WithEvents Ctltmp100 As CommandButton

再分別寫它的事件

Private Sub Ctltmp1_Click()
MsgBox "ctltmp100"
End Sub

.
.
.

Private Sub Ctltmp100_Click()
MsgBox "ctltmp100"
End Sub

有否簡單的方法?

如是這樣,那我還不如靜態新增好了,然後再設disable屬性了,而且簡單明了.

請指教?
...全文
30 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
klbt 2003-09-27
  • 打赏
  • 举报
回复
关注,帮你顶。

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧