很简单的,带小数点画即可,新建一工程,无需添加任何控件,拷贝下述代码,运行即可看到效果.
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
Private Type MyTimer
h As Single
m As Single
s As Single
End Type
Dim t As MyTimer
Private Sub drawTime()
'画指针,全部用一样长的指针
Const Pi = 3.1415926
Dim ox As Single, oy As Single, tx As Single, ty As Single, l As Single
Me.Cls
ox = Me.ScaleWidth * 0.5
oy = Me.ScaleHeight * 0.5
'原点坐标
l = Me.ScaleHeight * 0.3
'指针长度
tx = ox + l * Cos((t.h * 30 - 90) * Pi / 180)
ty = oy + l * Sin((t.h * 30 - 90) * Pi / 180)
Line (ox, oy)-(tx, ty), vbRed
tx = ox + l * Cos((t.m * 6 - 90) * Pi / 180)
ty = oy + l * Sin((t.m * 6 - 90) * Pi / 180)
Line (ox, oy)-(tx, ty), vbBlue
tx = ox + l * Cos((t.s * 6 - 90) * Pi / 180)
ty = oy + l * Sin((t.s * 6 - 90) * Pi / 180)
Line (ox, oy)-(tx, ty), vbBlack
End Sub
Private Sub Form_Load()
Dim i As Single, j As Long
Me.Show
i = Timer
While i <> 0
t.h = i / 3600
If t.h > 12 Then t.h = t.h - 12
t.m = (t.h - Int(t.h)) * 60
t.s = (t.m - Int(t.m)) * 60
i = Timer
drawTime
For j = 0 To 10000
DoEvents
Next
Wend
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub