动态加载用户控件后不能调用其属性方法的问题。如解决可以用2G的代码做为报答。

qyh 2002-08-22 12:58:15
关于动态加载用户控件的问题,我担心我说得不是很清楚,所有把代码贴出来。
测试方法:将下面那个控件生成FileOcx.Ocx,然后新建一个工程,在Form1中加入一个按钮,加入以下代码。
问题是:在不将FileOcx.Ocx添加到VB的控件箱中的前提下,我怎么才能成功调用FileOcx的FileName属性??
我不是想实现一个功能,我只是想成功调用FileOcx的FileName属性就行了。谢谢大家。

Dim WithEvents oControl As VBControlExtender
Private Function LoadControl()
Dim MyOCX As Control
Licenses.Add "FileOcx.FileLoad"
If Not oControl Is Nothing Then
Controls.Remove ("FileView")
End If
Set MyOCX = Controls.Add("FileOcx.FileLoad", "FileView")
MyOCX.FileName="C:\test.txt" '这里将会出错。
Set oControl = MyOCX
oControl.Height = 13500
oControl.Width = 16500
oControl.Top = 100
oControl.Visible = True
End Function

Private Sub Command1_Click()
LoadControl
End Sub
'============================================================
'============================================================


控件代码:
FileOcx.vbp文件
'============================================================
Type=Control
UserControl=FileLoad.ctl
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\WINNT\System32\stdole2.tlb#OLE Automation
Object={3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0; richtx32.ocx
Startup="(None)"
Command32=""
Name="FileOcx"
HelpContextID="0"
CompatibleMode="1"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=1
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
ThreadingModel=1
'======================================================

FileLoad.ctl文件
'======================================================
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
Begin VB.UserControl FileLoad
ClientHeight = 3600
ClientLeft = 0
ClientTop = 0
ClientWidth = 4800
ScaleHeight = 3600
ScaleWidth = 4800
Begin RichTextLib.RichTextBox RichTextBox1
Height = 3375
Left = 0
TabIndex = 0
Top = 0
Width = 4695
_ExtentX = 8281
_ExtentY = 5953
_Version = 393217
Enabled = -1 'True
TextRTF = $"FileLoad.ctx":0000
End
End
Attribute VB_Name = "FileLoad"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Const m_def_FileName = ""
Dim m_FileName As String
Public Property Get FileName() As String
FileName = m_FileName
End Property
Public Property Let FileName(ByVal New_FileName As String)
m_FileName = New_FileName
PropertyChanged "FileName"
End Property
Private Sub UserControl_InitProperties()
m_FileName = m_def_FileName
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_FileName = PropBag.ReadProperty("FileName", m_def_FileName)
End Sub

Private Sub UserControl_Resize()
RichTextBox1.Height = UserControl.Height
RichTextBox1.Width = UserControl.Width
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("FileName", m_FileName, m_def_FileName)
End Sub
...全文
263 15 打赏 收藏 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
qyh 2002-08-23
  • 打赏
  • 举报
回复
PFPF
ItSeeker 2002-08-23
  • 打赏
  • 举报
回复
'行啊
MyOCX.FileName="C:\test.txt"
该为
MyOCX.object.FileName = "C:\test.txt"
'呵呵
qyh 2002-08-22
  • 打赏
  • 举报
回复
还是不行,看来真的不行了
qyh 2002-08-22
  • 打赏
  • 举报
回复
非常感谢,我试一下。
ttyp 2002-08-22
  • 打赏
  • 举报
回复
可能是你得Licenses没有key,

看:Even if you clear the Require License Key option, a user control that contains third-party controls will still require a license key.

详细见下面:



Add Method (Licenses Collection)


Adds a license to the Licenses collection and returns the license key.

Syntax

object.Add (ProgID, LicenseKey)

The Add method syntax has these parts:

Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
ProgID Required. A string that specifies the control for which a license key will be added.
LicenseKey Optional. A string that specifies the license key.


Remarks

Use the Add method whenever you want to dynamically add a control that requires a license key. For more information about controls that require license keys, see "Licensing Issues for Controls" in the See Also list.

When you compile a user control that requires a license key, and you want to dynamically add that control to an existing application, you must use the Add method for the Licenses collection in two different ways.

First, use the method to return the license key that is hard-coded into a user control. Second, use the method to add the same license key to the Licenses collection before adding the user control to the Controls collection.

In most cases, you will have to use the method in both ways in order to properly deploy a compiled user control. The steps for this are outlined below.

After you have compiled a user control that requires a license key, use the Add method to return the license key. Store that license key where it can be retrieved by the deployed application. For example, the example below writes the key to a file. You could also store it in a database, or in the Windows registry.

Private Sub GenerateLicenseKey()
Dim intFile As Integer
intFile = FreeFile
' Open a file to write the license key to.
Open "c:\Temp\Ctl_Licenses.txt" For Output As #intFile
Dim strLicense As String
strLicense = Licenses.Add("prjWeeks.WeeksCtl")
' Write the license key to the file.
Write #intFile, strLicense
Close #intFile
End Sub

When you deploy your control, the deployed application adds the license key to the Licenses collection before adding the control to the Controls collection. (Of course, the control must have been installed on the machine as well.) The code example below adds the license key, then adds the control:

Option Explicit
Dim WithEvents extObj As VBControlExtender

Private Sub LoadDynamicControl()
Dim intFile As Integer
intFile = FreeFile
Open "c:\Download\Ctl_Licenses.txt" For Input As #intFile
Dim strKey As String
' On the client machine, read the license key from the file.
Input #intFile, strKey
Licenses.Add "prjWeeks.WeeksCtl", strKey
Close #intFile
Set extObj = Controls.Add("prjWeeks.WeeksCtl", "ctl1")
With Controls("ctl1")
.Visible = True
End With
End Sub

When To Add a License Key
When you create a user control and you want to distribute the control for dynamic control addition, you must consider the following question: Does the user control contain only intrinsic controls? If the answer is yes, then ask, "Do I want to require that the end user have a license key in order to use the control?" If the answer to both questions is "yes," then be sure to check the Require License Key option on the General tab of the Project Properties dialog box.

Note Even if you clear the Require License Key option, a user control that contains third-party controls will still require a license key.

When No License Key Is Needed
There are two circumstances when you do not have to add a license key in order to add a control to the Controls collection:

When the control is an intrinsic control and you have not checked the Require License Key option.


When you add a control that is referenced in the project. In other words, if the control is present in the Toolbox.
Note When you do have a control in the Toolbox and you plan to add that control only at run time, be sure to clear the Remove Information About Unused ActiveX Controls option on the Make tab of the Project Properties dialog box; otherwise, trying to add the control will fail.



qyh 2002-08-22
  • 打赏
  • 举报
回复
天,老大,你没有测试过吧,这样是不行的。

哎,看来没有办法了。
zyl910 2002-08-22
  • 打赏
  • 举报
回复
Private Function LoadControl()
Dim MyOCX As Control
Licenses.Add "FileOcx.FileLoad"
If Not oControl Is Nothing Then
Controls.Remove ("FileView")
End If
Set MyOCX = Controls.Add("FileOcx.FileLoad", "FileView")

Dim TempObj as Object
Set TempObj=MyOCX
TempObj.FileName="C:\test.txt"

……

End Function
junwhj 2002-08-22
  • 打赏
  • 举报
回复
我也遇到过,没有解决,收藏此贴!
qyh 2002-08-22
  • 打赏
  • 举报
回复
总之,谢谢楼上的了。
qyh 2002-08-22
  • 打赏
  • 举报
回复
真是麻烦,像Listview之类的控件是可以成功的,第三方控件就是不行,该死的VB。
shawls 2002-08-22
  • 打赏
  • 举报
回复
我也做过,没有成功,用withevents看看如何,sorry,没有办法帮助你
rushing 2002-08-22
  • 打赏
  • 举报
回复
再见。
qyh 2002-08-22
  • 打赏
  • 举报
回复
你以为2G的代码这么容易拿???
qyh 2002-08-22
  • 打赏
  • 举报
回复
看看题好不好!!!
rushing 2002-08-22
  • 打赏
  • 举报
回复
用regsvr32 注册你的控件。
在工程-〉部件中添加。
内容概要:本文围绕【复现IEEE二区文献】基于状态空间表示与组件连接法的构网型逆变器统一小信号建模框架研究,提出了一种适用于多控制策略构网型逆变器的小信号建模方法。该方法结合状态空间建模理论与组件连接法(Component Connection Method),实现了对复杂逆变器系统动态特性的精确描述,尤其适用于分析系统在不同运行工况下的稳定性。通过Matlab代码实现,构建了包含控制环路、滤波器、锁相环等关键模块的完整小信号模型,并利用特征值分析与模态参与度评估系统稳定性,解决了传统建模方法在面对多时间尺度、强耦合非线性控制结构时建模困难、精度不足的问题。研究还探讨了关键控制参数对系统稳定边界的影响,为构网型逆变器的参数整定与优化设计提供了理论依据和技术支撑。; 适合人群:具备电力电子、自动控制理论基础,从事新能源发电、微电网、电力系统稳定性研究的研究生、科研人员及工程技术人员,尤其适合致力于高水平期刊论文复现与仿真实践的科研工作者。; 使用场景及目标:① 掌握构网型逆变器统一小信号建模的核心方法,复现IEEE二区高水平文献成果;② 理解状态空间法与组件连接法在复杂电力电子系统建模中的集成应用;③ 利用Matlab进行特征值分析与稳定性判据研究,支撑科研仿真与论文写作;④ 为多逆变器并联系统、微电网稳定性分析等课题提供建模工具与技术路线参考。; 阅读建议:建议读者结合Matlab代码与文中建模流程逐步调试,重点关注各子模块状态方程的推导与系统整体矩阵组装过程,深入理解控制参数对系统极点分布的影响规律,建议配合其他稳定性分析案例进行对比学习以加深理解。
内容概要:WiFiSupply斯普莱WFS7000XB52AX5G是一款高性能、工业级的5G全网通+双频WIFI6无线AP基站,支持5G与工业大功率Wi-Fi链路无缝切换与带宽聚合,具备高达2974Mbps的双频带宽和1000Mbps以上的实际吞吐量。设备采用MIMO 4T4R架构,支持OFDMA、AI智能FastRoaming等先进技术,实现低至20ms的漫游切换延迟和超远传输距离(点对点桥接可达150公里以上)。产品具备IP68防水、-45~85℃宽温运行、多重看门狗、防浪涌、防静电等工业级防护设计,适用于复杂恶劣环境。支持胖瘦AP模式、多种认证与管理方式(含云平台、API接口),并集成丰富的网络安全与QoS功能,适用于智慧物流、工业4.0、巡检机器人、无人机、车载船舶等多种场景。; 适合人群:从事工业物联网、智能制造、自动化物流、智能交通等领域的网络工程师、系统集成商、设备制造商及技术决策人员。; 使用场景及目标:①实现移动设备(如AGV/AMR/巡检机器人)在高速移动中的零丢包、低延迟无线漫游;②在无固定网络覆盖区域构建高带宽、高可靠的远距离无线通信链路;③为5G与工业Wi-Fi双链路备份与聚合提供一体化解决方案,保障关键业务连续性;④在复杂电磁环境下实现稳定、安全的数据传输与远程控制。; 阅读建议:本产品技术参数详尽,建议结合具体应用场景重点关注其无线性能、漫游技术、供电方式与安装选项,并参考官方提供的管理平台与API接口文档进行系统集成与远程运维规划。

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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