1. 在程序中注册和注销 ocx 控件 98-7-20
声明(在本例子里使用的是 comctl32.ocx,如果是其他,使用相应的名称):
declare function regcomctl32 lib "comctl32.ocx" _
alias "dllregisterserver" () as long
declare function unregcomctl32 lib "comctl32.ocx" _
alias "dllunregisterserver" () as long
const error_success = &h0
使用:
if regcomctl32 = error_success then
msgbox "registration successful"
else
msgbox "registration unsuccessful"
end if
if unregcomctl32 = error_success then
msgbox "unregistration successful"
else
msgbox "unregistration unsuccessful"
end if
2.建立可下拉选择的属性
例如在 borderstyle 中有以下的四个选择:
0 - none
1 - dashed
2 - single line
3 - double line
4 - 3d
首先在控件中定义以下的集合:
enum bordertype
none
dashed
[single line]
[double line]
[3d]
end enum
然后就可以把属性的类型设置好:
public property get borderstyle() as bordertype
border = m_borderstyle
end property
public property let borderstyle(byval new_borderstyle as bordertype)
m_borderstyle = new_borderstyle
propertychanged "borderstyle"
end property
3.缺省值和可选参数
vb5 加强了函数参数方面,可用以下的代码实现参数缺省:
property get value(optional index as long = 1)
...
end property
也可使用另一个方法(慢):
property get value(optional index as long)
if ismissing(index) then index = 1
...
end property
4.多个参数的属性
在自制的控件中,可能需要对某个属性传递多个值:
property let test (arg1 as string, arg2 as string, arg3 as integer)
end property
用以下的方法传递参数:
test(arg1,arg2) = arg3
5.使用数组做属性
定义一个 variant 类型的属性,即可用它来做数组。
下面定义了一个 carray 类。
private m_myarray as variant
public property get myarray() as variant
myarray = m_myarray
end property
public property let myarray as variant)
m_myarray = a
end property
可用以下的方法使用:
private m_array as carray
private marr(3) as string
private sub form_load()
set m_array = new carray
marr(1) = "one"
marr(2) = "two"
marr(3) = "three"
m_array.myarray = marr()
或者
m_array.myarray = array("one", "two", "three")
end sub
private sub form_unload(cancel as integer)
dim i as integer
for i = 1 to ubound(m_array.myarray)
msgbox m_array.myarray(i)
next
end sub
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器