作业帮 > 综合 > 作业

用VB编一个钟表,表针运动程序怎么编?

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/18 10:01:58
用VB编一个钟表,表针运动程序怎么编?
我用VB编了一个钟表,可表针(不是数字!)1秒1秒在变动,怎么编写这段程序?
这个比较麻烦,我曾经写过这么个程序片段,现在贴上来,代码比较复杂
Shape1是时钟的一个框,是Shape控件,设置 Height 1455 Width 1575
LineHour,LineMinute,LineSecond分别为时,分,秒针,为Line控件
Label3,Label6,Label9,Label12为Label控件,分别为3.6.912点的显示数字
再画个Timer控件,Interval设置为1000
以上控件位置随便放,代码里调整
Form_Load事件里写
Shape1.Top = 100
Shape1.Left = Me.Width - 1800
LineHour.X1 = Shape1.Left + Shape1.Width / 2
LineHour.Y1 = Shape1.Top + Shape1.Height / 2
LineMinute.X1 = Shape1.Left + Shape1.Width / 2
LineMinute.Y1 = Shape1.Top + Shape1.Height / 2
LineSecond.X1 = Shape1.Left + Shape1.Width / 2
LineSecond.Y1 = Shape1.Top + Shape1.Height / 2
Label3.Left = Shape1.Left + Shape1.Width - Label3.Width - 200
Label3.Top = Shape1.Top + (Shape1.Height - Label3.Height) / 2
Label6.Left = Shape1.Left + (Shape1.Width - Label6.Width) / 2
Label6.Top = Shape1.Top + Shape1.Height - Label6.Height + 20
Label9.Left = Shape1.Left + 200
Label9.Top = Shape1.Top + (Shape1.Height - Label9.Height) / 2
Label12.Left = Shape1.Left + (Shape1.Width - Label12.Width) / 2
Label12.Top = Shape1.Top + 100
Timer事件里写
'利用Label显示数字
If Shape1.Visible True Then Shape1.Visible = True
If LineHour.Visible True Then LineHour.Visible = True
If LineMinute.Visible True Then LineMinute.Visible = True
If LineSecond.Visible True Then LineSecond.Visible = True
If Label3.Visible True Then Label3.Visible = True
If Label6.Visible True Then Label6.Visible = True
If Label9.Visible True Then Label9.Visible = True
If Label12.Visible True Then Label12.Visible = True
Dim cx As Single,cy As Single '圆心坐标
cx = Shape1.Left + Shape1.Width / 2
cy = Shape1.Top + Shape1.Height / 2
'利用Line控件绘制指针
LineSecond.X2 = LineSecond.X1 + Sin(CLng(Second(Now)) / 60 * 2 * pi) * 480
LineSecond.Y2 = LineSecond.Y1 - Cos(CLng(Second(Now)) / 60 * 2 * pi) * 480
LineMinute.X2 = LineMinute.X1 + Sin(CLng(Minute(Now)) / 60 * 2 * pi) * 360
LineMinute.Y2 = LineMinute.Y1 - Cos(CLng(Minute(Now)) / 60 * 2 * pi) * 360
LineHour.X2 = LineHour.X1 + Sin((CLng(Hour(Now)) + CLng(Minute(Now)) / 60) / 12 * 2 * pi) * 240
LineHour.Y2 = LineHour.Y1 - Cos((CLng(Hour(Now)) + CLng(Minute(Now)) / 60) / 12 * 2 * pi) * 240
'利用Line方法绘制刻度
Me.Line (cx + 250,cy - 433.012701892219)-(cx + 300,cy - 519.615242270663)
Me.Line (cx + 433.012701892219,cy - 250)-(cx + 519.615242270663,cy - 300)
Me.Line (cx + 433.012701892219,cy + 250)-(cx + 519.615242270663,cy + 300)
Me.Line (cx + 250,cy + 433.012701892219)-(cx + 300,cy + 519.615242270663)
Me.Line (cx - 250,cy + 433.012701892219)-(cx - 300,cy + 519.615242270663)
Me.Line (cx - 433.012701892219,cy + 250)-(cx - 519.615242270663,cy + 300)
Me.Line (cx - 433.012701892219,cy - 250)-(cx - 519.615242270663,cy - 300)
Me.Line (cx - 250,cy - 433.012701892219)-(cx - 300,cy - 519.615242270663)