用VB编写一个闹钟程序

用VB编写一个闹钟程序,第1张

做一个简单的闹钟程序很简单的。我颂唤这里不用if语句。首先我们在窗体上添加一个标腔绝签控件,再画一个“闹钟”,将闹钟得interval属野圆凯性改为1000,双击闹钟,进入闹钟的代码视图,编写代码

private

sub

timer1_timer()

label1.caption

=

time

end

sub就行了。谢谢采纳

下面是一个时钟程序代码,你可以参考一下。

Const PI = 3.14159265

Dim H, W, R As Integer '窗体高、宽、圆半径

Private Sub BiaoKe()

Dim I As Integer

'外盘

Circle (W \ 2, H \胡衡 2), R, vbBlue

'中心

Circle (W \ 2, H \ 2), 1, vbWhite

'盘面各点

For I = 0 To 59

If I Mod 5 = 0 Then

Circle (W \ 2 + R * Cos(I * PI / 30), H \ 2 + R * Sin(I * PI / 30)), 2, vbGreen

Else

Circle (W \ 2 + R * Cos(I * PI / 30), H \ 2 + R * Sin(I * PI / 30)), 1, vbWhite

End If

Next I

End Sub

Private Sub Form_Load()

Me.Show

Me.Cls

H = frmTime.ScaleHeight

W = frmTime.ScaleWidth

R = W \ 4

lbTime.Left = (frmTime.ScaleWidth - lbTime.Width) \ 2

lbTime.Top = frmTime.ScaleHeight - R \ 4

End Sub

Private Sub Form_Resize()

Call Form_Load

End Sub

Private Sub Timer1_Timer()

Dim T1, T2, T3 As Integer

Dim I, J, K As Integer

Me.Cls

T1 = Hour(Time): T2 = Minute(Time): T3 = Second(Time)

I = T1 - 15

J = T2 - 15

K = T3 - 15

'钟表裤岩做外壳

Call BiaoKe

'画时针

Line (W \ 2, H \ 2)-(W \ 2 + 0.5 * (R * Cos((I + J / 60) * PI / 6)), H \ 2 + 0.5 * (R * Sin((I + J / 60) * PI / 6))), vbGreen

'画分针

Line (W \ 2, H \ 2)-(W \ 2 + 0.7 * (R * Cos((J + K / 60) * PI / 30)), H \ 2 + 0.7 * (R * Sin((J + K / 60) * PI /枣伍 30))), vbYellow

'画秒针

Line (W \ 2, H \ 2)-(W \ 2 + 0.9 * (R * Cos(K * PI / 30)), H \ 2 + 0.9 * (R * Sin(K * PI / 30))), vbRed

K = K + 1

If K >360 Then K = K Mod 360

lbTime.Caption = Time

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8242691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存