Relevant knowledge of self-made controls

xiaoxiao2021-03-06  36

Relevant knowledge of self-made controls

Register and log out of the program 98-7-20 declaration (used in this example is comctl32.ocx, if you are other, use the corresponding name): Declare function regomctl32 lib "chactl32.ocx" _ alias "dllregisterServer" () As long declare function unregcomctl32 lib "comctl32.ocx" _ alias "dllunregisterServer" () as long const error_success = & h0

use:

If regcomctl32 = error_success kilobox "registration successful" else msgbox "registration unsuccessful" endiff

If unregcomctl32 = error_success the msgbox "unregistration successful" else msgbox "unregistration unsuccessful" endiff

2. Establishing a drop-down option, for example, there are four options in BorderStyle: 0 - None 1 - Dashed 2 - Single Line 3 - Double Line 4 - 3D First Defining the following Collection in the control: Enum bordertype none dashed [ Single line] [double line] [3D] End enum then set the type of property to the type: Public property get border () as bordertype border = m_borderstyle End Property

Public Property Let Border (Byval New_Bordersty AS BorderType) M_Borderstyle = New_Borderstyle PropertyChanged "BorderStyle" End Property

3. The default value and optional parameter VB5 enhances the function parameters, and the following code can be used to implement parameters default:

Property Get Value (Optional Index As Long = 1) ... End Property can also use another method (slow):

Property Get Value (OPTIONAL INDEX As Long) IF Ismissing (Index) THEN INDEX = 1 ... End Property

4. The properties of multiple parameters are in the homemade control, and you may need to pass multiple values ​​for a property:

Property Let Test (Arg1 AS String, Arg2 AS String, Arg3 AS Integer) End Property

'Transfer parameters with the following method: Test (arg1, arg2) = arg3

5. Using the array to define a Variant type property, you can use it to do arrays. The following defines a Carray class.

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 can be used in the following methods:

Private M_Array As Carray Private Marr (3) AS STRING

Private suform_load () set m_array = new carray marr (1) = "one" marr (2) = "two" marr (3) = "three" m_Array.myArray = marr () or '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

转载请注明原文地址:https://www.9cbs.com/read-70687.html

New Post(0)