Developing ActiveX Controls Using Visual Basic(3)

 

Example: Clock Control

1.      Start VB and choose project type to be ActiveX Control

2.      Name the project prjClock, name the form uctClock

3.      Place a label on the form, name it lblTime, give it a caption of “”. Set the background color to your choice, and also the foreground color.

4.      Place a timer on the form. Set the interval to 500 (milliseconds)

5.      The code should look like:

Private Sub Timer1_Timer()

 lblTime.Caption = Time

End Sub

Private Sub UserControl_Initialize()

 lblTime.Width = UserControl.ScaleWidth

 lblTime.Height = UserControl.ScaleHeight

End Sub

Private Sub UserControl_Resize()

 lblTime.Left = UserControl.ScaleLeft

 lblTime.Top = UserControl.ScaleTop

 lblTime.Width = UserControl.ScaleWidth

 lblTime.Height = UserControl.ScaleHeight

End Sub

6.      From the build menu, choose Make prjClock.ocx. Choose an appropriate directory to place the ocx file.

7.      Run Regedit to find the Class ID of the prjClock ActiveX control.

Here is the html file that will use the ActiveX Clock Control designed above.

<!-- clockctl.htm -->

<HTML>

<HEAD>

<TITLE> Clock Control Test</TITLE>

<H1> ActiveX Control in a Web Page </H1>

</HEAD>

<BODY>

<PRE>

<object classid="clsid:A24D787B-2AFF-11D4-9F02-00A0CC28BB43" name=clkct1

   width=200 height=50 codebase=”c:"vb6progs"prjClock.ocx”>

<FORM NAME=frmCalc method="" action="">

 <input name=t1>

</FORM>

</BODY>

</HTML>

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

导航