资源描述
首先打开vb6.0,新建一个工程,在窗体中放一个imagebox控件然后在其中放一个timer控件再就是一个直线控件数组注意要把imagebox中的stretch属性改为true,直线控件数组是14个,要注意下面是我和程序代码,有一些注解的希望能对大家有帮助Private Sub Form_Load() 设置窗体和计时器参数Timer1.Interval = 100 设置计时器事件间隔是1/10秒Width = 4000Height = 4000Left = Screen.Width 2 - 2000Top = (Screen.Height - Height) 2End SubPrivate Sub Form_Resize() 启动时和改变窗体时设置刻度和指针 Dim i, angle For i = 0 To 13 Line1(i).Visible = True Line1(i).BorderWidth = 4 If i = 0 Or i 12 Then Line1(i).BorderColor = RGB(0, 0, 128) Else Line1(i).BorderColor = RGB(0, 128, 0) End If Next i Line1(12).BorderColor = RGB(128, 256, 128) Line1(9).BorderColor = RGB(256, 128, 128) Line1(6).BorderColor = RGB(128, 0, 256) Line1(3).BorderColor = RGB(0, 0, 255) Line1(13).BorderColor = RGB(255, 0, 255) Line1(0).BorderWidth = 5 时针的粗细 Line1(14).BorderWidth = 2 分针的粗细 Line1(i).BorderColor = RGB(256, 0, 0) For i = 0 To 14 Scale (-1, 1)-(1, -1) 画出表盘12个点和时,分.秒15条线 angle = i * 2 * Atn(1) / 3 Line1(i).X1 = 0.9 * Cos(angle) Line1(i).Y1 = 0.9 * Sin(angle) Line1(i).X2 = Cos(angle) Line1(i).Y2 = Sin(angle) Next i End SubPrivate Sub Timer1_Timer() Const hh = 0 Const mh = 13 Const sh = 14 Dim angle Static ls If Second(Now) = ls Then Exit Sub 机器时钟停止程序退出 ls = Second(Now) angle = 0.5236 * (15 - (Hour(Now) + Minute(Now) / 60) 时钟转动设置 Line1(hh).X1 = 0 Line1(hh).Y1 = 0 Line1(hh).X2 = 0.3 * Cos(angle) Line1(hh).Y2 = 0.3 * Sin(angle) angle = 0.1047 * (75 - (Minute(Now) + Second(Now) / 60) 分钟转动设置 Line1(mh).X1 = 0 Line1(mh).Y1 = 0 Line1(mh).X2 = 0.7 * Cos(angle) Line1(mh).Y2 = 0.7 * Sin(angle) angle = 0.5236 * (75 - Second(Now) / 5) 秒钟转动设置 Line1(sh).X1 = 0 Line1(sh).Y1 = 0 Line1(sh).X2 = 0.8 * Cos(angle) Line1(sh).Y2 = 0.8 * Sin(angle) Form1.Caption = Str(Now() 窗口显示日期和时间 End Sub
展开阅读全文