请教:在窗体上画一直线,用vb把这条直线设计成象钟表的秒针一样在运动。谢谢。
Timer1.Interval = 500
Form1.Height = 8085
Form1.Width = 9225
End Sub
Private Sub Timer1_Timer()
Cls
Scale (-2000, 2000)-(3000, -2200)
Line (0, 0)-(1000 * Sin(Second(Time) / 60 * 6.28), 1000 * Cos(Second(Time) / 60 * 6.28)), 255
Line (0, 0)-(800 * Sin(Minute(Time) / 60 * 6.28), 800 * Cos(Minute(Time) / 60 * 6.28)), 200
If Hour(Time) > 12 Then
Line (0, 0)-(600 * Sin((Hour(Time) - 12) / 12 * 6.28), 600 * Cos((Hour(Time) - 12) / 12 * 6.28)), 0
Else
Line (0, 0)-(600 * Sin(Hour(Time) / 12 * 6.28), 600 * Cos(Hour(Time) / 12 * 6.28)), 0
End If
Circle (0, 0), 1000
End Sub
2023-08-15 广告
Private Sub Form_Load()
Picture1.AutoRedraw = True '允许重绘
Picture1.Height = 2500
Picture1.Width = 2500
'自定义坐标系
Picture1.Scale (-100, -100)-(100, 100)
'确定指针的初始位置
Line2.X1 = 0
Line2.Y1 = 0
Line1.X1 = 0
Line1.Y1 = 0
Line3.X1 = 0
Line3.Y1 = 0
'确定边框位置
Shape1.Top = -95
Shape1.Left = -95
Shape1.Width = 190
Shape1.Height = 190
'激活定时器
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Label1.Caption = "现在时间是:" + Str(Time)
'下列语句用于绘制秒针
sx = Sin((180 - 6 * Second(Time)) * 3.14159 / 180) * 85
sy = Cos((180 - 6 * Second(Time)) * 3.14159 / 180) * 85
Line3.X2 = sx
Line3.Y2 = sy
'下列语句用于绘制分针
mx = Sin((180 - 6 * Minute(Time)) * 3.14159 / 180) * 70
my = Cos((180 - 6 * Minute(Time)) * 3.14159 / 180) * 70
Line2.X2 = mx
Line2.Y2 = my
'下列语句用于绘制时针
hx = Sin((180 - (30 * Hour(Time) + 30 * Minute(Time) / 60)) * 3.14159 / 180) * 50
hy = Cos((180 - (30 * Hour(Time) + 30 * Minute(Time) / 60)) * 3.14159 / 180) * 50
Line1.X2 = hx
Line1.Y2 = hy
'下列语句用于在指定位置打印时钟刻度
Picture1.CurrentX = -2
Picture1.CurrentY = 80
Picture1.Print "6"
Picture1.CurrentX = -8
Picture1.CurrentY = -95
Picture1.Print "12"
Picture1.CurrentX = 85
Picture1.CurrentY = -8
Picture1.Print "3"
Picture1.CurrentX = -90
Picture1.CurrentY = -8
Picture1.Print "9"
End Sub