很详细的时钟程序(使用line控件手画表盘表针)
Option Explicit'Line3 表示时针
'Line1(1) 表示分针(长度960)
'Line2 表示秒针(长度1200)
'Timer 定时器周期1s
'Label2 标签显示当前系统时间
Dim xx1 As Integer '表盘圆心坐标
Dim yy1 As Integer
Dim MyTime, MyHour, MyMinute, MySecond As Integer '定义当前时间,时,分,秒
Dim S_ang, M_ang, H_ang As Single '定义角度变量
Dim S_rad, M_rad, H_rad As Single '定义弧度变量
Dim S_Length, M_Length, H_Length As Integer '定义表针长度变量
Private Sub Form_Load()
xx1 = 2280 '由属性确定圆心坐标
yy1 = 1920
Line3.X1 = xx1 '校准表盘坐标原点
Line3.Y1 = yy1
Line1(1).X1 = xx1
Line1(1).Y1 = yy1
Line2.X1 = xx1
Line2.Y1 = yy1
MyTime = Now '暂存当前时间值
MySecond = Second(MyTime) '读取秒
MyMinute = Minute(MyTime) '读取分
MyHour = Hour(MyTime) '读取时
M_ang = MyMinute * 6 '任意一点分针角度
M_rad = (3.14 / 180) * M_ang
H_ang = MyHour * 30 '任意一点时针角度
H_rad = (3.14 / 180) * H_ang
Line1(1).X2 = Line1(1).X1 + (960 * Sin(M_rad)) '计算X2,Y2转动坐标 (以单位圆Y轴为0度)
Line1(1).Y2 = Line1(1).Y1 - (960 * Cos(M_rad))
Line3.X2 = Line3.X1 + (720 * Sin(H_rad)) '计算X2,Y2转动坐标 (以单位圆Y轴为0度)
Line3.Y2 = Line3.Y1 - (720 * Cos(H_rad))
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Now
MyTime = Now '暂存当前时间值
MySecond = Second(MyTime) '读取秒
Label15.Caption = MySecond
MyMinute = Minute(MyTime) '读取分
Label18.Caption = MyMinute
MyHour = Hour(MyTime) '读取时
Label20.Caption = MyHour
S_ang = MySecond * 6 '任意一点秒针角度
M_ang = MyMinute * 6 '任意一点分针角度
M_rad = (3.14 / 180) * M_ang
H_ang = MyHour * 30 '任意一点时针角度
H_rad = (3.14 / 180) * H_ang
S_rad = (3.14 / 180) * S_ang
Line2.X2 = Line2.X1 + (1200 * Sin(S_rad)) '计算X2,Y2转动坐标 (以单位圆Y轴为0度)
Line2.Y2 = Line2.Y1 - (1200 * Cos(S_rad))
If MySecond = 59 Then
Line1(1).X2 = Line1(1).X1 + (960 * Sin(M_rad)) '计算X2,Y2转动坐标 (以单位圆Y轴为0度)
Line1(1).Y2 = Line1(1).Y1 - (960 * Cos(M_rad))
ElseIf MyMinute = 59 Then
Line3.X2 = Line3.X1 + (720 * Sin(H_rad)) '计算X2,Y2转动坐标 (以单位圆Y轴为0度)
Line3.Y2 = Line3.Y1 - (720 * Cos(H_rad))
End If
End Sub
请看到的朋友们,挑毛病找缺陷。