有关在dll中动态向主程序窗体加载控件的问题dll中类名ClsTest 工程名MyTest
dim withevents objCmd as VB.CommandButtonpublic sub Init(frm as Form)
set objCmd=form.controls.add("VB.CommandButton","objCmd").
ojcmd.visible=true
end sub
在dll中写
sub objCmd_CLick()
msgbox "testing"
end sub编译为MyTest.dll然后另开一工程调用这个dll
主程序:添加一Form窗体。一按钮CommandButton1
private Sub CommandButton_Click()
dim aa as object
set aa=createobject("MyTest.dll")
aa.init me
end sub问题: 添加的按钮的单击事件没有响应,就是没有弹出testing消息。
dim withevents objCmd as VB.CommandButtonpublic sub Init(frm as Form)
set objCmd=form.controls.add("VB.CommandButton","objCmd").
ojcmd.visible=true
end sub
在dll中写
sub objCmd_CLick()
msgbox "testing"
end sub编译为MyTest.dll然后另开一工程调用这个dll
主程序:添加一Form窗体。一按钮CommandButton1
private Sub CommandButton_Click()
dim aa as object
set aa=createobject("MyTest.dll")
aa.init me
end sub问题: 添加的按钮的单击事件没有响应,就是没有弹出testing消息。
Set aa= New MyTest
選擇你的dll
msgbox "testing"
end sub
==========================================================
你没有事件触发它,怎么会运行呢?dim withevents objCmd as VB.CommandButtonpublic sub Init(frm as Form)
set objCmd=form.controls.add("VB.CommandButton","objCmd").
ojcmd.visible=true
end sub
在dll中写
sub objCmd_CLick()
msgbox "testing"
end sub编译为MyTest.dll然后另开一工程调用这个dll
主程序:添加一Form窗体。一按钮CommandButton1
private Sub CommandButton_Click()
dim aa as ClsTest
set aa=New ClsTest
aa.init me
call objCmd_CLick
end sub
另外:本人,没有蔑视任何人的意思。所谓菜鸟就是那种不看问题本身,随便跟贴的人。我觉得我的问题已经说的很明白了,那种随便跟贴的人根本就没有去研究我的问题所在。其实你随便按我写的步骤演绎一下,就可以看到效果,纸上谈兵是没用的。
你不也是刚刚才学 掉DLL里的东西吗!但楼上大哥别骂人啊 他是也菜鸟的 和我们一样的
public sub Init(frm as Form)
set objCmd=form.controls.add("VB.CommandButton","objCmd").
' ^^^^^
ojcmd.visible=true
end sub
应该是 frm.controls.add 吧
set objCmd=frm.controls.add("VB.CommandButton","objCmd").
'left,top,height,width需要指定
ojcmd.visible=true
end sub