我用VB编好了一个时钟的程序,如下,我怎么修改可以让程序中的时针、分针...
发布网友
发布时间:2024-10-14 14:25
我来回答
共4个回答
热心网友
时间:2024-10-27 09:50
添加一个Timer时钟控件,把Timer1的Interval值设为1000,把Form_Load()事件里的代码移到Timer_Timer()事件里
Const pi = 3.1415926
Private Sub Timer1_Timer()
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
lins.X2 = lins.X1 + 3200 * Sin(6 * s * pi / 180)
lins.Y2 = lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
linf.X2 = linf.X1 + 2600 * Sin(6 * m * pi / 180)
linf.Y2 = linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
linh.X2 = linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
linh.Y2 = linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub
热心网友
时间:2024-10-27 09:55
吧Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
lins.X2 = lins.X1 + 3200 * Sin(6 * s * pi / 180)
lins.Y2 = lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
linf.X2 = linf.X1 + 2600 * Sin(6 * m * pi / 180)
linf.Y2 = linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
linh.X2 = linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
linh.Y2 = linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)这一段放到一个timer控件的过程里就行了,Interval设为100(0.1秒刷新)或1000(1秒刷新)。
热心网友
时间:2024-10-27 09:52
用一个TIMER控件,把代码放到TIMER里面去
Const pi = 3.1415926
Private Sub Form_Load()
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
Lins.X2 = Lins.X1 + 3200 * Sin(6 * s * pi / 180)
Lins.Y2 = Lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
Linf.X2 = Linf.X1 + 2600 * Sin(6 * m * pi / 180)
Linf.Y2 = Linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
Linh.X2 = Linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
Linh.Y2 = Linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub
Private Sub Timer1_Timer()
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
Lins.X2 = Lins.X1 + 3200 * Sin(6 * s * pi / 180)
Lins.Y2 = Lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
Linf.X2 = Linf.X1 + 2600 * Sin(6 * m * pi / 180)
Linf.Y2 = Linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
Linh.X2 = Linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
Linh.Y2 = Linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub
热心网友
时间:2024-10-27 09:57
没有定义各线的初始位置,直接调到窗口中心吧,加个timer控件:
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Const pi = 3.1415926
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
Line1.X1 = Me.Width / 2
Line3.X1 = Me.Width / 2
Line2.X1 = Me.Width / 2
Line1.Y1 = Me.Height / 2
Line2.Y1 = Me.Height / 2
Line3.Y1 = Me.Height / 2
Line1.X2 = Line1.X1 + 3200 * Sin(6 * s * pi / 180)
Line1.Y2 = Line1.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
Line2.X2 = Line2.X1 + 2600 * Sin(6 * m * pi / 180)
Line2.Y2 = Line2.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
Line3.X2 = Line3.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
Line3.Y2 = Line3.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub