📄 clock2.ctl
字号:
VERSION 5.00
Begin VB.UserControl UserControl1
ClientHeight = 3045
ClientLeft = 0
ClientTop = 0
ClientWidth = 3165
ScaleHeight = 3045
ScaleWidth = 3165
Begin VB.PictureBox Picture1
BackColor = &H00FFFFFF&
Height = 3015
Left = 0
Picture = "clock2.ctx":0000
ScaleHeight = 2955
ScaleWidth = 3075
TabIndex = 0
Top = 0
Width = 3135
Begin VB.Timer Timer1
Interval = 1000
Left = 120
Top = 120
End
Begin VB.Line Line3
BorderColor = &H0000FF00&
BorderWidth = 5
X1 = 720
X2 = 1560
Y1 = 1440
Y2 = 1440
End
Begin VB.Line Line2
BorderColor = &H0000FFFF&
BorderWidth = 3
X1 = 2640
X2 = 1560
Y1 = 1440
Y2 = 1440
End
Begin VB.Line Line1
BorderColor = &H000000FF&
X1 = 1560
X2 = 1560
Y1 = 240
Y2 = 1440
End
Begin VB.Shape Shape2
BackColor = &H000000FF&
BackStyle = 1 'Opaque
Height = 135
Index = 3
Left = 2880
Top = 1360
Width = 135
End
Begin VB.Shape Shape2
BackColor = &H000000FF&
BackStyle = 1 'Opaque
Height = 135
Index = 2
Left = 1500
Top = 2760
Width = 135
End
Begin VB.Shape Shape2
BackColor = &H000000FF&
BackStyle = 1 'Opaque
Height = 135
Index = 1
Left = 0
Top = 1360
Width = 135
End
Begin VB.Shape Shape1
BackColor = &H00000000&
BackStyle = 1 'Opaque
BorderColor = &H00404040&
Height = 255
Left = 1440
Shape = 2 'Oval
Top = 1320
Width = 255
End
Begin VB.Shape Shape2
BackColor = &H000000FF&
BackStyle = 1 'Opaque
Height = 135
Index = 0
Left = 1500
Top = 0
Width = 135
End
End
End
Attribute VB_Name = "UserControl1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Const DX = 1440
Const DY = 1320
Const PI = 3.14159265
Private sl As Long
Private ml As Long
Private hl As Long
Private Sub Timer1_Timer()
Dim s As Integer
Dim m As Integer
Dim h As Integer
'获得小时
h = Hour(Time)
'获得分钟
m = Minute(Time)
'获得秒
s = Second(Time)
If h >= 12 Then h = h - 12
'根据取得的时间决定表针的指向
Line1.X1 = sl * Cos((s - 60) * 2 * PI / 60 - PI / 2) + DX
Line1.Y1 = sl * Sin((s - 60) * 2 * PI / 60 - PI / 2) + DY
Line2.X1 = ml * Cos((m - 60) * 2 * PI / 60 - PI / 2) + DX
Line2.Y1 = ml * Sin((m - 60) * 2 * PI / 60 - PI / 2) + DY
Line3.X1 = hl * Cos((h - 12) * 2 * PI / 12 - PI / 2) + DX
Line3.Y1 = hl * Sin((h - 12) * 2 * PI / 12 - PI / 2) + DY
End Sub
Private Sub UserControl_Initialize()
Dim s As Integer
Dim m As Integer
Dim h As Integer
'获得小时
h = Hour(Time)
'获得分钟
m = Minute(Time)
'获得秒
s = Second(Time)
If h >= 12 Then h = h - 12
'计算秒针、分针和时针的长度
sl = Sqr((Line1.X2 - Line1.X1) ^ 2 + (Line1.Y1 - Line1.Y2) ^ 2)
ml = Sqr((Line2.X2 - Line2.X1) ^ 2 + (Line2.Y1 - Line2.Y2) ^ 2)
hl = Sqr((Line3.X2 - Line3.X1) ^ 2 + (Line3.Y1 - Line3.Y2) ^ 2)
'根据取得的时间决定表针的指向
Line1.X1 = sl * Cos((s - 60) * 2 * PI / 60 - PI / 2) + DX
Line1.Y1 = sl * Sin((s - 60) * 2 * PI / 60 - PI / 2) + DY
Line2.X1 = ml * Cos((m - 60) * 2 * PI / 60 - PI / 2) + DX
Line2.Y1 = ml * Sin((m - 60) * 2 * PI / 60 - PI / 2) + DY
Line3.X1 = hl * Cos((h - 12) * 2 * PI / 12 - PI / 2) + DX
Line3.Y1 = hl * Sin((h - 12) * 2 * PI / 12 - PI / 2) + DY
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -