VB中时钟的运用
展开全部
VB可使用Timer控件、Line控件和绘图或加载图片等制作指针式时钟。
Timer 控件,通过引发 Timer 事件,Timer 控件可以有规律地隔一段时间执行一次代码。
Line 控件,Line 控件是图形控件,它显示水平线、垂直线或者对角线。
运行时不能使用 Move 方法移动 Line 控件,但是可以通过改变 X1、X2、Y1 和 Y2 属性来移动它或者调整它的大小。
Circle 方法,在对象上画圆、椭圆或弧。
以下是通过加载图片的指针式时钟代码:
Option Explicit Private Const PI = 3.1415926 Dim X(1) As Single, Y(1) As Single Dim OriAngle As Single, DestAngle As Single, r As SinglePrivate Sub RotateLine(objL As Line, bsPointX As Single, bsPointY As Single, RotateAngle As Single) With objL X(0) = .X1 Y(0) = .Y1 X(1) = .X2 Y(1) = .Y2 End With Dim i As Integer For i = 0 To 1 If X(i) - bsPointX <> 0 Then OriAngle = Atn((Y(i) - bsPointY) / (X(i) - bsPointX)) Else OriAngle = IIf(Y(i) > bsPointY, PI / 2, 1.5 * PI) End If If X(i) - bsPointX < 0 Then If OriAngle < 0 Then OriAngle = PI - Abs(OriAngle) Else OriAngle = PI + Abs(OriAngle) End If End If DestAngle = OriAngle + RotateAngle r = Sqr((X(i) - bsPointX) ^ 2 + (Y(i) - bsPointY) ^ 2) X(i) = bsPointX + r * Cos(DestAngle) Y(i) = bsPointY + r * Sin(DestAngle) Next i With objL .X1 = X(0) .Y1 = Y(0) .X2 = X(1) .Y2 = Y(1) End WithEnd SubPrivate Sub Form_Load() Timer1.Interval = 1000 Dim i As Long For i = 1 To Val(Mid(Time$, 7, 2)) RotateLine Line3, Line3.X1, Line3.Y1, 1 * PI / 30 Next For i = 1 To Val(Mid(Time$, 4, 2)) RotateLine Line2, Line2.X1, Line2.Y1, 1 * PI / 30 Next For i = 1 To Val(Mid(Time$, 1, 2)) * 5 '对时针 RotateLine Line1, Line1.X1, Line1.Y1, 1 * PI / 30 Next For i = 1 To Val(Mid(Time$, 4, 2)) '对时针 RotateLine Line1, Line1.X1, Line1.Y1, 1 * PI / 360 NextEnd SubPrivate Sub Timer1_Timer() RotateLine Line3, Line3.X1, Line3.Y1, 1 * PI / 30 RotateLine Line2, Line2.X1, Line2.Y1, PI / 1800 If Mid(Time$, 7, 2) = "00" Or Mid(Time$, 7, 2) = "30" Then RotateLine Line1, Line1.X1, Line1.Y1, 1 * PI / 720 End If Me.Caption = Time$End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询