Developing ActiveX Controls Using Visual Basic(1)

 

Example: Color Control

  1. Start VB and choose project type to be ActiveX Control
  2. Name the project prjCol, name the form ucol
  3. From the Project->Components menu, select “Microsoft Common Dialog Control 6.0”. It will get added to the toolbox.
  4. Place a button on the form, name it cmdColor, give it a caption of “Choose Color”.
  5. 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

  1. From the build menu, choose Make prjCol.ocx. Choose an appropriate directory to place the ocx file.
  2. Run Regedit to find the Class ID of the prjCol ActiveX control.

posted on 2008-03-12 15:52  squll201  阅读(115)  评论(0)    收藏  举报

导航