Developing ActiveX Controls Using Visual Basic(1)
Example: Color Control
- Start VB and choose project type to be ActiveX Control
- Name the project prjCol, name the form ucol
- From the Project->Components menu, select “Microsoft Common Dialog Control 6.0”. It will get added to the toolbox.
- Place a button on the form, name it cmdColor, give it a caption of “Choose Color”.
- Double Click on the “Choose Color” button to write the code. The code should look like:
Public Event ColorClick()
Private Sub cmdColor_Click()
cd1.ShowColor
RaiseEvent ColorClick
End Sub
Private Sub UserControl_Resize()
cmdColor.Move 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight
End Sub
Public Property Get Color() As Variant
Color = cd1.Color
End Property
- From the build menu, choose Make prjCol.ocx. Choose an appropriate directory to place the ocx file.
- Run Regedit to find the Class ID of the prjCol ActiveX control.
浙公网安备 33010602011771号