vb做时钟
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
建立一个空窗体(保证是正方体),拖入一个时钟控件,再将下面代码粘贴在代码窗体里,运行。
Const PAI = 3.1415926
Dim t As Boolean
Private Sub Form_Load()
Timer1.Enabled = True '激活时钟控件
paintclock 'callpaintclock
Form3.AutoRedraw = True
Form3.ScaleMode = 3
End Sub
Private Sub Timer1_Timer()
Dim ang
Me.Cls
paintclock
If Hour(Now) < 12 Then
ang = Hour(Now) * PAI / 6 + Minute(Now) * PAI / (6 * 60)
Else
ang = (Hour(Now) - 12) * PAI / 6 + Minute(Now) * PAI / (6 * 60)
End If
X1 = 0
Y1 = 0
X2 = 0.4 * Sin(ang)
Y2 = 0.4 * Cos(ang)
DrawWidth = 3
Me.Line (X1, Y1)-(X2, Y2), vbBlack
ang = Minute(Now) * PAI / 30 + Second(Now) * PAI / (30 * 60)
X1 = 0
Y2 = 0
X2 = 0.7 * Sin(ang)
Y2 = 0.7 * Cos(ang)
DrawWidth = 1.5
Me.Line (X1, Y1)-(X2, Y2), vbBlack
ang = Second(Now) * PAI / 30
X1 = 0
Y1 = 0
X2 = 0.8 * Sin(ang)
Y2 = 0.8 * Cos(ang)
DrawWidth = 1
Me.Line (X1, Y1)-(X2, Y2), vbBlack
End Sub
Private Sub paintclock()
Dim i As Integer, ang
For i = 0 To 11
Scale (-1, 1)-(1, -1) '
ang = i * 2 * PAI / 12
X1 = 0.9 * Cos(ang)
Y1 = 0.9 * Sin(ang)
X2 = Cos(ang)
Y2 = Sin(ang)
DrawWidth = 2
Me.Line (X1, Y1)-(X2, Y2), RGB(92, 80, 250) '
Next i
For i = 0 To 59
Scale (-1, 1)-(1, -1) '
ang = i * 2 * PAI / 60
X1 = 0.98 * Cos(ang)
Y1 = 0.98 * Sin(ang)
X2 = Cos(ang)
Y2 = Sin(ang)
DrawWidth = 1
Me.Line (X1, Y1)-(X2, Y2), vbBlack '
Next i
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then ' if windowstate=2 then will belive big Timer1.Enabled = False
Else
Timer1.Enabled = True
End If
End Sub