注册 登录
编程论坛 VB6论坛

指针式钟表,秒针怎么走的准??

txxb 发布于 2014-12-18 19:23, 665 次点击
按照课程做了个指针式钟表,秒针是一秒一秒跳着走的,
能不能让它匀速转动??
3 回复
#2
smart30002014-12-18 21:00
在timer控件中定期重画秒针,每0.1秒重画一次
#3
xzlxzlxzl2014-12-18 21:30
很简单的,带小数点画即可,新建一工程,无需添加任何控件,拷贝下述代码,运行即可看到效果.
只有本站会员才能查看附件,请 登录

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
#4
txxb2014-12-18 22:01
厉害啊,我要慢慢的才看的懂
1