为什么用Control.Add加入的控件无法访问其属性、方法?但是可以响应事件。
但是用CreateObject就是访问属性、方法。
但是用CreateObject就是访问属性、方法。
解决方案 »
- 延时处理问题
- 可以贴图了,试试 :)
- SQL Server版沉下去了,希望在VB版能顶起来,随便散散分。。。
- 有时间的请看,200元急求一VB简单程序。
- 一个简单的问题,关于鼠标右键弹出菜单的
- 关于mscomm的使用
- 请问我在使用set xlapp=new excel.application实现excel报表,但问题是当使用rang("k6")=rs!je,系统出错.
- 如何用程序设置输入法,比如我想启动程序后,将输入法自动切换为中文
- 第二贴了:大家帮忙看看,下面的代码能在串口读字符串,可是如何实十六进制的读取
- DBCombo与Addnew!急!!!!!!!
- 大家一起来想
- 谁有 把阴历 转换为 公历 的源码??
Option ExplicitPrivate Sub Command1_Click()
Dim opt1 As OptionButton, opt2 As OptionButton
Set opt1 = Controls.Add("VB.OptionButton", "opt1", Frame1)
Set opt2 = Controls.Add("VB.OptionButton", "opt2", Frame1)
With opt1
.Left = 200
.Top = 400
.Height = 200
.Width = 1000
.Caption = "Option1"
.Visible = True
End WithWith opt2
.Left = 200
.Top = 800
.Height = 200
.Width = 1000
.Caption = "Option2"
.Visible = True
End WithEnd Sub
Private WithEvents btnObj As CommandButton
Private Sub btnObj_Click()
MsgBox "这是动态添加的按钮。"
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
这里使用WithEvent指定动态添加的控件的事件
Set btnObj = Controls.Add("工程序名.控件名", "btnObj") with btnObj
.method (为你写的方法)end with(工程名为你的自定义控件工程名)
你写的控件和那里面的控件有区别吗?只要是ActiveX控件,就没区别了!
如果你非要这么干建议你不要用vb,干脆用汇编
不会被通过
因为自己写的控件不在一个工程,是一个已经编译好的文件。To crazyxf(网海鲨鱼) ( ) :
非也,我是有特殊运用
dim btnObj as 控件名没有被通过只能说明你这个部件没有正确注册或控件本身有问题
在运行时用Control.Add 加入的控件和你在设计时手动加入的控件没啥区别的 ,一样可以访问属性方法
是我用Liscense.Add添加的
另外,现在总结一下问题1、该控件如果静态调用能访问到方法
2、如果该控件放到同一个工程里面,动态、静态调用都能访问到方法
因为控件名是不固定的,在运行时我读取配置文件才能得到。
所以,我现在是
Private WithEvents objOcx As VBControlExtender
……
另外奉献Form_Load的代码
Private Sub Form_Load()
'读取数据
Dim strParam As String
strParam = GetParam(m_ConfigID) Dim ConfigProgID As String
Dim DriverID As String
DriverID = Trim(GetKeyVal(SYS_PATH + CONFIG_INI, CONFIG_PREFIX + m_ConfigID, "DriverID"))
ConfigProgID = Trim(GetKeyVal(SYS_PATH + DRIVER_INI, DRIVER_PREFIX + DriverID, "ConfigProgID")) '相当于动态引用该工程
Licenses.Add ConfigProgID
VB.Clipboard.SetText strParam
Set objOcx = Me.Controls.Add(ConfigProgID, "objOcx", Me.fraParam)
'MsgBox objOcx.PrintA
fraParam.Width = objOcx.Width + BORDER * 2
fraParam.Height = objOcx.Height + BORDER * 4
cmdClose.Top = fraParam.Top + fraParam.Height + BORDER
cmdSave.Top = cmdClose.Top
cmdClose.Left = fraParam.Left + fraParam.Width - cmdClose.Width
cmdSave.Left = cmdClose.Left - cmdSave.Width - BORDER
Me.Width = fraParam.Width + BORDER * 4
Me.Height = fraParam.Height + cmdClose.Height + txtConfigName.Height * 2 + BORDER * 10
objOcx.Top = BORDER * 2
objOcx.Left = BORDER
objOcx.Visible = True
Call ShowConfig(m_ConfigID)
End Sub