【文件属性】:
文件名称:为控件添加属性-OCX制作开发
文件大小:377KB
文件格式:PPT
更新时间:2021-04-25 09:32:06
OCX ActiveX VB控件
6.为控件添加属性
如为控件增加Drive属性的步骤为:
(1)打开ActiveX 控件设计窗口的代码窗口。
(2)单击“工具”菜单中的“添加过程”,打开“添加过程”对话框,输入属性名“Drive”,过程类型为“属性”,范围为“公有的”。
这样,VB立即提供如下两个过程模板:
Public Property Get Drive() As Variant
End Property
Public Property Let Drive(ByVal vNewValue As Variant)
End Property
在这两个过程中添加所需代码:
Public Property Get Drive() As String
Drive = Drive1.Drive
End Property
Public Property Let Drive(ByVal New_Drive As String)
Drive1.Drive = New_Drive
End Property
这样,就将UserControl对象子控件Drive1的Drive属性显露出来,关闭ActiveX 控件设计窗口,在属性窗口可以看到Drive属性,参见图14-6(Drive的默认值设置为“c:”。在程序运行时,在驱动器列表中选择的驱动器就是ActiveX 控件的Drive属性值。