在该控件(Myctl)中定义一个事件用来表示用户点击了按钮,比如说 public event PostButtonClicked() '在控件的该按钮的click中fire此事件 private sub command1_click() ...... raiseevent PostButtonClicked end sub 在你定义的窗体中该控件的PostButtonClicked中添加事件的脚本: private sub Myctl_PostButtonClicked() ....... unload me end sub
运行时添加的?使用VBControlExtender对象?假设控件工程名prjCtl,控件名如上Myctl Private WithEvents oMyctl As VBControlExtender 在窗体Load中添加: Licenses.Add "prjCtl.Myctl" Set oCtlDX = Me.Controls.Add(mc_"prjCtl.Myctl", mc_oMyctl )Private Sub oMyctl_ObjectEvent(Info As EventInfo) Select Case Info.name case "PostButtonClicked" unload me case else end select end sub
不好意思前面 Set oCtlDX = Me.Controls.Add(mc_"prjCtl.Myctl", mc_oMyctl )中 的那两个mc_不要,应该为 Set oCtlDX = Me.Controls.Add("prjCtl.Myctl", oMyctl )
public event PostButtonClicked()
'在控件的该按钮的click中fire此事件
private sub command1_click()
......
raiseevent PostButtonClicked
end sub
在你定义的窗体中该控件的PostButtonClicked中添加事件的脚本:
private sub Myctl_PostButtonClicked()
.......
unload me
end sub
Private WithEvents oMyctl As VBControlExtender
在窗体Load中添加:
Licenses.Add "prjCtl.Myctl"
Set oCtlDX = Me.Controls.Add(mc_"prjCtl.Myctl", mc_oMyctl )Private Sub oMyctl_ObjectEvent(Info As EventInfo)
Select Case Info.name
case "PostButtonClicked"
unload me
case else
end select
end sub
Set oCtlDX = Me.Controls.Add(mc_"prjCtl.Myctl", mc_oMyctl )中
的那两个mc_不要,应该为
Set oCtlDX = Me.Controls.Add("prjCtl.Myctl", oMyctl )