Public Property Get Enabled() As Boolean
Enabled = Command1.Enabled
End Property
Public Property Let Enabled(ByVal New_Enabled As Boolean)
Command1.Enabled() = New_Enabled
PropertyChanged "Enabled"
End Property
Public Property Get Picture() As Picture
Set Picture = Command1.Picture
End Property
Public Property Set Picture(ByVal New_Picture As Picture)
Set Command1.Picture = New_Picture
PropertyChanged "Picture"
End Property
Public Property Get Font() As Font
Set Font = Command1.Font
End Property
Public Property Set Font(ByVal New_Font As Font)
Set Command1.Font = New_Font
PropertyChanged "Font"
End Property
Public Sub Refresh()
Command1.Refresh
End Sub
Public Property Get Interval() As Long
Interval = Timer1.Interval
End Property
Public Property Let Interval(ByVal New_Interval As Long)
Timer1.Interval() = New_Interval
PropertyChanged "Interval"
End Property
Public Property Get Caption() As String
Caption = Command1.Caption
End Property
Public Property Let Caption(ByVal New_Caption As String)
Command1.Caption() = New_Caption
PropertyChanged "Caption"
End Property
完成对以上工作的保存,然后用鼠标选择菜单“文件”中的“生成OCX”选项,在Visual Basic 集成开发环境中就会弹出一个询问路径和文件名称的对话框,在列表框中和“文件名”文本框中选择合适的路径和名称后,单击“保存”按钮,Visual Basic 就会自动的生成自定义的ActiveX控件。
重新启动Visual Basic ,在屏幕上弹出的“新建工程”对话框中选择“标准EXE”选项,单击“打开”按钮,启动一个标准的工程项目,同时打开了一个空白的窗体。选择菜单“工程”中的“部件”选项,在屏幕上就会弹出一个如图8-13所示的“部件”对话框。

图8-13 “部件”对话框
单击“部件”对话框中的“浏览”按钮来选择刚才制作的ActiveX控件,单击“应用”按钮就可以把自定义的ActiveX控件加载到当前的项目文件中,并且在程序设计的过程中把自定义的ActiveX控件添加到窗体上,其中窗体和控件的属性设置如下所示。
Begin Visual Basic .Form Form1
Caption = "Form1"
ClientTop = 345
ClientWidth = 6225
ScaleHeight = 4170
ScaleWidth = 6225
StartUpPosition = 3
Begin 工程1.UserControl1 UserControl11
Height = 615
Left = 1320
Interval = 500
Top = 720
Width = 2775
Caption = "1997:1:1"
End
End
经过以上属性设置后的窗体如图8-14所示。

图8-14 经过属性设置后的程序窗体
在程序设计的过程中,用鼠标双击窗体上的自定义ActiveX控件,在屏幕上就会弹出一个代码窗口,把光标移动到事件Private Sub UserControl11_Timer()的处理过程中,并且添加如下所示的响应代码。
Private Sub UserControl11_Timer()
Form1.UserControl11.Caption = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)
'设置控件显示内容
End Sub
由于把自定义ActiveX控件的Interval属性设置为500,所以每隔500微秒就会激活一个Private Sub UserControl11_Timer()事件,程序通过代码Form1.UserControl11.Caption = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)在自定义ActiverX控件上动态的显示系统当前的时间。
存储文件,运行程序,结果如图8-15所示。

图8-15 程序运行结果
以上我们介绍了自定义ActiveX控件的制作过程,其实作为ActiveX技术本身来讲,最吸引人的地方还是如何将ActiveX控件发布到网络上,即ActiveX文档技术。
其实在Visual Basic 6中制作在网络上发布的ActiveX文档并不是很困难的事情,下面就以示例程序来说明。
首先启动一个新的Visual Basic 6项目,在屏幕上就会弹出一个“新建工程”对话框,在其中选择“ActiveX Document EXE”选项,在Visual Basic 6的集成开发环境中就会自动的启动一个ActiveX文档工程,如图8-16所示。

图8-16 新建的ActiveX文档工程
在键盘上按下功能键[Ctrl+R]激活工程资源管理器,把系统默认的用户文档UserDocument1删除,然后选择菜单“工程”中的“添加窗体”选项,在屏幕上就会弹出一个如图8-17所示的对话框。

图8-17 “添加窗体”对话框
在“添加窗体”对话框中选择“窗体”选项,单击“打开”按钮,系统就会把一个标准的空白窗体添加到当前的ActiveX文档工程中。
的空白窗体添加到当前的ActiveX文档工程中。
在程序设计的过程中,向当前空白的窗体上放置两个Frame控件、两个CheckBox控件、一个TextBox控件、三个OptionButton控件和一个ListBox控件,它们的属性设置如下所示。
Begin Visual Basic .Form Form1
StartUpPosition = 3
Begin Visual Basic .Frame Frame2
Caption = "字体名称:"
Begin Visual Basic .ListBox List1
Height = 1860
Left = 120
Top = 240
Width = 2775
End
End
Begin Visual Basic .Frame Frame1
Caption = "字体风格:"
Begin Visual Basic .OptionButton Option1
Caption = "斜体"
Index = 2
End
Begin Visual Basic .OptionButton Option1
Caption = "粗斜体"
Index = 3
End
Begin Visual Basic .OptionButton Option1
Caption = "粗体"
Index = 1
End
Begin Visual Basic .CheckBox Check1
Caption = "删除线"
Index = 1
End
Begin Visual Basic .CheckBox Check1
Caption = "下划线"
Index = 0
End
End
Begin Visual Basic .TextBox Text1
Text = "Text1"
End
End
添加控件后的窗体如图8-18所示。

图8-18 添加控件后的窗体
它们的作用如下:
n TextBox控件:用来演示设置字体属性的各种效果;
n ListBox控件:在程序运行的过程中显示系统字体;
n CheckBox控件:为用户选择字体下划线和删除线的形式提供容器;
n OptionButton控件:为用户选择字体粗体和斜体的形式提供容器;
n Frame控件:充当控件容器。
用鼠标双击窗体,在弹出的代码窗口中选择程序初始化事件Private Sub Form_Load(),并且添加如下所示的响应代码。
Private Sub Form_Load()
Form1.Text1.Font = "宋体"
Form1.Text1.FontBold = True
Form1.Text1.FontItalic = False
Form1.Text1.FontStrikethru = False
'初始化文本框中的字体
For i = 0 To Screen.FontCount - 1 Step 1
Form1.List1.AddItem Screen.Fonts(i), i
Next
'向列表框中添加系统字体
End Sub
在程序运行的初期,Private Sub Form_Load()事件中的代码就被执行,程序首先通过四条语句初始化文本框中的字体形式为宋体、黑体,并且没有下划线和删除线,然后通过一个循环语句向窗体中的列表框控件添加系统字体。