轉帖|其它|編輯:郝浩|2010-10-19 15:26:57.000|閱讀 521 次
概述:本文主要介紹自己開發控件需要注意的事項,希望對大家有幫助。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
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 加強了函數參數方面,可用以下的代碼實現參數缺?。?/p>
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(a 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
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:博客轉載