怎么用VB来制作时钟
发布网友
发布时间:2022-05-29 21:36
我来回答
共4个回答
热心网友
时间:2024-11-03 16:06
下面是全部代码
只要把这些复制到一个空白的txt文件里
再把扩展名txt改成frm
就可以直接运行了
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 375
Left = 3240
TabIndex = 0
Top = 2520
Width = 1215
End
Begin VB.Timer Timer1
Left = 1800
Top = 1320
End
Begin VB.Label Label1
Height = 375
Left = 1440
TabIndex = 1
Top = 2520
Width = 1095
End
Begin VB.Shape Shape1
Height = 495
Left = 360
Shape = 3 'Circle
Top = 2040
Width = 495
End
Begin VB.Line Line2
X1 = 240
X2 = 1800
Y1 = 720
Y2 = 720
End
Begin VB.Line Line1
BorderWidth = 2
X1 = 360
X2 = 1920
Y1 = 360
Y2 = 360
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Line1 代表时针
'Line2 代表分针
Dim X0 As Integer, Y0 As Integer
Dim L As Integer
Const Pi = 3.1415926
Private Sub Command1_Click()
Do
h = Int(Val(InputBox("请输入你需要的小时数:", "修改", Hour(Now))))
Loop Until h >= 0 And h < 24
Do
m = Int(Val(InputBox("请输入你需要的分钟数:", "修改", Minute(Now))))
Loop Until m >= 0 And m < 60
Do
s = Int(Val(InputBox("请输入你需要的秒数:", "修改", Second(Now))))
Loop Until s >= 0 And s < 60
Label1 = Trim(Str(h)) & ":" & Trim(Str(m)) & ":" & Trim(Str(s))
End Sub
Private Sub Form_Activate()
For DU = 0 To 354 Step 6 '画秒刻度
xd = Cos(DU * Pi / 180) * (L - 100) + X0
yd = Sin(DU * Pi / 180) * (L - 100) + Y0
PSet (xd, yd), RGB(0, 0, 0)
Next
Me.FillColor = RGB(200, 200, 200)
For DU = 0 To 330 Step 30 '画5秒刻度
xd = Cos(DU * Pi / 180) * (L - 100) + X0
yd = Sin(DU * Pi / 180) * (L - 100) + Y0
Circle (xd, yd), 25
xd = Cos(DU * Pi / 180) * (L - 250) + X0
yd = Sin(DU * Pi / 180) * (L - 250) + Y0
CurrentX = xd - 100
CurrentY = yd - 100
If DU > 270 Then '写数字
Print DU / 30 - 9
Else
If DU = 270 Then CurrentX = CurrentX - 80
Print DU / 30 + 3
End If
Next
Me.FillColor = RGB(250, 100, 100) '画15秒刻度
For DU = 0 To 270 Step 90
xd = Cos(DU * Pi / 180) * (L - 100) + X0
yd = Sin(DU * Pi / 180) * (L - 100) + Y0
Circle (xd, yd), 40, RGB(0, 0, 255)
Next
End Sub
Private Sub Form_Load()
L = 2000 '长度基准,也是表盘的半径
Me.AutoRedraw = True
Me.Width = 4 * L
Me.Height = 3.5 * L
Me.FillColor = RGB(120, 250, 250)
Me.FillStyle = 0
X0 = Me.Width / 2 - 40
Y0 = Me.Height / 2 - 400
Line1.X1 = X0
Line1.Y1 = Y0
Line1.BorderWidth = 3
Line2.X1 = X0
Line2.Y1 = Y0
Line2.BorderWidth = 2
Shape1.Shape = 3 '秒针
Shape1.FillColor = RGB(255, 0, 0)
Shape1.FillStyle = 0
Shape1.Height = L / 12
Shape1.Width = L / 12
Shape1.BorderStyle = 0
Circle (X0, Y0), L '表盘
Me.FillColor = RGB(250, 0, 0)
Me.Circle (X0, Y0), L / 40, RGB(255, 0, 0) '中心
Timer1.Interval = 1000
Call Timer1_Timer
Command1.Caption = "修改时间"
Command1.Top = Me.Height - L * 3 / 4
Command1.Left = Me.Width - L * 3 / 4
Command1.Height = L / 3
Label1.Top = Command1.Top
Label1.Left = Width / 4
Label1.Width = Width / 3
Label1.FontSize = 24
Label1.Height = Command1.Height
Label1.Caption = ""
End Sub
Private Sub Timer1_Timer()
If Label1 = "" Then
t = Time
Else
t = CDate(Label1) + 1 / 24 / 60 / 60
End If
DU = Second(t) * 6 - 90 '制作秒针
Shape1.Top = Sin(DU * Pi / 180) * L * 0.85 + Y0 - Shape1.Height / 2
Shape1.Left = Cos(DU * Pi / 180) * L * 0.85 + X0 - Shape1.Width / 2
m = L * 0.7 '制作分针
DU = Minute(t) * 6 - 90 '+ Second(T) * 6 / 60
Line2.X2 = Cos(DU * Pi / 180) * m + X0
Line2.Y2 = Sin(DU * Pi / 180) * m + Y0
h = L * 0.6 '制作时针
DU = (Hour(t) Mod 12) * 30 + Minute(t) * 6 / 12 - 90
Line1.X2 = Cos(DU * Pi / 180) * h + X0
Line1.Y2 = Sin(DU * Pi / 180) * h + Y0
Label1 = t
End Sub
热心网友
时间:2024-11-03 16:07
复制到一个空白的txt文件里
再把扩展名txt改成frm
就可以直接运行了
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 375
Left = 3240
TabIndex = 0
Top = 2520
Width = 1215
End
Begin VB.Timer Timer1
Left = 1800
Top = 1320
End
Begin VB.Label Label1
Height = 375
Left = 1440
TabIndex = 1
Top = 2520
Width = 1095
End
Begin VB.Shape Shape1
Height = 495
Left = 360
Shape = 3 'Circle
Top = 2040
Width = 495
End
Begin VB.Line Line2
X1 = 240
X2 = 1800
Y1 = 720
Y2 = 720
End
Begin VB.Line Line1
BorderWidth = 2
X1 = 360
X2 = 1920
Y1 = 360
Y2 = 360
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Line1 代表时针
'Line2 代表分针
Dim X0 As Integer, Y0 As Integer
Dim L As Integer
Const Pi = 3.1415926
Private Sub Command1_Click()
Do
h = Int(Val(InputBox("请输入你需要的小时数:", "修改", Hour(Now))))
Loop Until h >= 0 And h < 24
Do
m = Int(Val(InputBox("请输入你需要的分钟数:", "修改", Minute(Now))))
Loop Until m >= 0 And m < 60
Do
s = Int(Val(InputBox("请输入你需要的秒数:", "修改", Second(Now))))
Loop Until s >= 0 And s < 60
Label1 = Trim(Str(h)) & ":" & Trim(Str(m)) & ":" & Trim(Str(s))
End Sub
Private Sub Form_Activate()
For DU = 0 To 354 Step 6 '画秒刻度
xd = Cos(DU * Pi / 180) * (L - 100) + X0
yd = Sin(DU * Pi / 180) * (L - 100) + Y0
PSet (xd, yd), RGB(0, 0, 0)
Next
Me.FillColor = RGB(200, 200, 200)
For DU = 0 To 330 Step 30 '画5秒刻度
xd = Cos(DU * Pi / 180) * (L - 100) + X0
yd = Sin(DU * Pi / 180) * (L - 100) + Y0
Circle (xd, yd), 25
xd = Cos(DU * Pi / 180) * (L - 250) + X0
yd = Sin(DU * Pi / 180) * (L - 250) + Y0
CurrentX = xd - 100
CurrentY = yd - 100
If DU > 270 Then '写数字
Print DU / 30 - 9
Else
If DU = 270 Then CurrentX = CurrentX - 80
Print DU / 30 + 3
End If
Next
Me.FillColor = RGB(250, 100, 100) '画15秒刻度
For DU = 0 To 270 Step 90
xd = Cos(DU * Pi / 180) * (L - 100) + X0
yd = Sin(DU * Pi / 180) * (L - 100) + Y0
Circle (xd, yd), 40, RGB(0, 0, 255)
Next
End Sub
Private Sub Form_Load()
L = 2000 '长度基准,也是表盘的半径
Me.AutoRedraw = True
Me.Width = 4 * L
Me.Height = 3.5 * L
Me.FillColor = RGB(120, 250, 250)
Me.FillStyle = 0
X0 = Me.Width / 2 - 40
Y0 = Me.Height / 2 - 400
Line1.X1 = X0
Line1.Y1 = Y0
Line1.BorderWidth = 3
Line2.X1 = X0
Line2.Y1 = Y0
Line2.BorderWidth = 2
Shape1.Shape = 3 '秒针
Shape1.FillColor = RGB(255, 0, 0)
Shape1.FillStyle = 0
Shape1.Height = L / 12
Shape1.Width = L / 12
Shape1.BorderStyle = 0
Circle (X0, Y0), L '表盘
Me.FillColor = RGB(250, 0, 0)
Me.Circle (X0, Y0), L / 40, RGB(255, 0, 0) '中心
Timer1.Interval = 1000
Call Timer1_Timer
Command1.Caption = "修改时间"
Command1.Top = Me.Height - L * 3 / 4
Command1.Left = Me.Width - L * 3 / 4
Command1.Height = L / 3
Label1.Top = Command1.Top
Label1.Left = Width / 4
Label1.Width = Width / 3
Label1.FontSize = 24
Label1.Height = Command1.Height
Label1.Caption = ""
End Sub
Private Sub Timer1_Timer()
If Label1 = "" Then
t = Time
Else
t = CDate(Label1) + 1 / 24 / 60 / 60
End If
DU = Second(t) * 6 - 90 '制作秒针
Shape1.Top = Sin(DU * Pi / 180) * L * 0.85 + Y0 - Shape1.Height / 2
Shape1.Left = Cos(DU * Pi / 180) * L * 0.85 + X0 - Shape1.Width / 2
m = L * 0.7 '制作分针
DU = Minute(t) * 6 - 90 '+ Second(T) * 6 / 60
Line2.X2 = Cos(DU * Pi / 180) * m + X0
Line2.Y2 = Sin(DU * Pi / 180) * m + Y0
h = L * 0.6 '制作时针
DU = (Hour(t) Mod 12) * 30 + Minute(t) * 6 / 12 - 90
Line1.X2 = Cos(DU * Pi / 180) * h + X0
Line1.Y2 = Sin(DU * Pi / 180) * h + Y0
Label1 = t
End Sub
热心网友
时间:2024-11-03 16:07
将下面的代码复制到文本文件里,再把扩展名txt改成frm
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 3990
ClientLeft = 45
ClientTop = 330
ClientWidth = 4170
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3990
ScaleWidth = 4170
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 375
Left = 0
TabIndex = 12
Text = "Text1"
Top = 0
Width = 855
End
Begin VB.Timer Timer1
Interval = 1
Left = 0
Top = 1080
End
Begin VB.Line Line3
X1 = 2000
X2 = 2000
Y1 = 700
Y2 = 2000
End
Begin VB.Line Line2
X1 = 3000
X2 = 2000
Y1 = 3000
Y2 = 2000
End
Begin VB.Line Line1
X1 = 2000
X2 = 2000
Y1 = 1000
Y2 = 2000
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "12"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 11
Left = 1800
TabIndex = 11
Top = 480
Width = 330
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "11"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 10
Left = 1200
TabIndex = 10
Top = 720
Width = 330
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "10"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 9
Left = 720
TabIndex = 9
Top = 1200
Width = 330
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "9"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 8
Left = 600
TabIndex = 8
Top = 1800
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "8"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 7
Left = 720
TabIndex = 7
Top = 2520
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "7"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 6
Left = 1200
TabIndex = 6
Top = 3000
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "6"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 5
Left = 1920
TabIndex = 5
Top = 3200
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "5"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 4
Left = 2640
TabIndex = 4
Top = 3000
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "4"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 3
Left = 3000
TabIndex = 3
Top = 2520
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "3"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 2
Left = 3240
TabIndex = 2
Top = 1800
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "2"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 1
Left = 3120
TabIndex = 1
Top = 1200
Width = 165
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "1"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Index = 0
Left = 2640
TabIndex = 0
Top = 720
Width = 165
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Timer1_Timer()
Form1.Circle (2000, 2000), 1500
Form1.Circle (2000, 2000), 50
s = Right(Time(), 2)
m = Left(Right(Time(), 5), 2)
h = Val(Left(Time(), 2) & "." & (m * 1.7))
Line3.Y1 = 2000 - (Cos(s * 6 / 57.3)) * 1300
Line3.X1 = 2000 + (Sin(s * 6 / 57.3)) * 1300
Line2.Y1 = 2000 - (Cos(m * 6 / 57.3)) * 1100
Line2.X1 = 2000 + (Sin(m * 6 / 57.3)) * 1100
Line1.Y1 = 2000 - (Cos(h * 30 / 57.3)) * 900
Line1.X1 = 2000 + (Sin(h * 30 / 57.3)) * 900
Text1.Text = Time
End Sub
热心网友
时间:2024-11-03 16:08
建一个text 一个timer
在timer中写入代码:
text1.text=now
时间循环为100
ok