最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > VB开发

VB教程:自制控件方面的有关知识

日期:09-14    来源:中国设计秀    作者:cnwebshow.com

1. ork中国设计秀
在程序中注册和注销 OCX 控件 98-7-20 ork中国设计秀
声明(在本例子里使用的是 ComCtl32.OCX,如果是其他,使用相应的名称): ork中国设计秀
Declare Function RegComCtl32 Lib "ComCtl32.OCX" _ ork中国设计秀
Alias "DllRegisterServer" () As Long ork中国设计秀
Declare Function UnRegComCtl32 Lib "ComCtl32.OCX" _ ork中国设计秀
Alias "DllUnregisterServer" () As Long ork中国设计秀
Const ERROR_SUCCESS = &H0 ork中国设计秀
ork中国设计秀
使用: ork中国设计秀
ork中国设计秀
If RegComCtl32 = ERROR_SUCCESS Then ork中国设计秀
MsgBox "Registration Successful" ork中国设计秀
Else ork中国设计秀
MsgBox "Registration Unsuccessful" ork中国设计秀
End If ork中国设计秀
ork中国设计秀
If UnRegComCtl32 = ERROR_SUCCESS Then ork中国设计秀
MsgBox "UnRegistration Successful" ork中国设计秀
Else ork中国设计秀
MsgBox "UnRegistration Unsuccessful" ork中国设计秀
End If ork中国设计秀
ork中国设计秀
2. ork中国设计秀
建立可下拉选择的属性 ork中国设计秀
例如在 BorderStyle 中有以下的四个选择: ork中国设计秀
0 - None ork中国设计秀
1 - Dashed ork中国设计秀
2 - Single Line ork中国设计秀
3 - Double Line ork中国设计秀
4 - 3D ork中国设计秀
首先在控件中定义以下的集合: ork中国设计秀
Enum BorderType ork中国设计秀
None ork中国设计秀
Dashed ork中国设计秀
[Single Line] ork中国设计秀
[Double Line] ork中国设计秀
[3D] ork中国设计秀
End Enum ork中国设计秀
然后就可以把属性的类型设置好: ork中国设计秀
Public Property Get BorderStyle() As BorderType ork中国设计秀
Border = m_BorderStyle ork中国设计秀
End Property ork中国设计秀
ork中国设计秀
Public Property Let BorderStyle(ByVal New_BorderStyle As BorderType) ork中国设计秀
m_BorderStyle = New_BorderStyle ork中国设计秀
PropertyChanged "BorderStyle" ork中国设计秀
End Property ork中国设计秀
ork中国设计秀
3. ork中国设计秀
缺省值和可选参数 ork中国设计秀
VB5 加强了函数参数方面,可用以下的代码实现参数缺省: ork中国设计秀
ork中国设计秀
Property Get Value(Optional index As Long = 1) ork中国设计秀
... ork中国设计秀
End Property ork中国设计秀
也可使用另一个方法(慢): ork中国设计秀
ork中国设计秀
Property Get Value(Optional index As Long) ork中国设计秀
If IsMissing(index) Then index = 1 ork中国设计秀
... ork中国设计秀
End Property ork中国设计秀
ork中国设计秀
4. ork中国设计秀
多个参数的属性 ork中国设计秀
在自制的控件中,可能需要对某个属性传递多个值: ork中国设计秀
ork中国设计秀
Property Let Test (arg1 As String, arg2 As String, arg3 As Integer) ork中国设计秀
End Property ork中国设计秀
ork中国设计秀
'用以下的方法传递参数: ork中国设计秀
Test(arg1,arg2) = arg3 ork中国设计秀
ork中国设计秀
5. ork中国设计秀
使用数组做属性 ork中国设计秀
定义一个 variant 类型的属性,即可用它来做数组。 ork中国设计秀
下面定义了一个 CArray 类。 ork中国设计秀
ork中国设计秀
Private m_MyArray As Variant ork中国设计秀
ork中国设计秀
Public Property Get MyArray() As Variant ork中国设计秀
MyArray = m_MyArray ork中国设计秀
End Property ork中国设计秀
ork中国设计秀
Public Property Let MyArray(a As Variant) ork中国设计秀
m_MyArray = a ork中国设计秀
End Property ork中国设计秀
ork中国设计秀
可用以下的方法使用: ork中国设计秀
ork中国设计秀
Private m_Array As CArray ork中国设计秀
Private mArr(3) As String ork中国设计秀
ork中国设计秀
Private Sub Form_Load() ork中国设计秀
Set m_Array = New CArray ork中国设计秀
mArr(1) = "One" ork中国设计秀
mArr(2) = "Two" ork中国设计秀
mArr(3) = "Three" ork中国设计秀
m_Array.MyArray = mArr() ork中国设计秀
'或者 ork中国设计秀
'm_Array.MyArray = Array("One", "Two", "Three") ork中国设计秀
End Sub ork中国设计秀
ork中国设计秀
Private Sub Form_Unload(Cancel As Integer) ork中国设计秀
Dim i As Integer ork中国设计秀
For i = 1 To UBound(m_Array.MyArray) ork中国设计秀
MsgBox m_Array.MyArray(i) ork中国设计秀
Next ork中国设计秀
End Subork中国设计秀

 ork中国设计秀

本文引用地址:/bc/article_61278.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明