怎么用VB来制作时钟

希望能用到下面的语句:PrivateSubForm_Load()DimsAsInteger,MAsInteger,HAsIntegerlen_s=Sqr((lineS.Y... 希望能用到下面的语句:
Private Sub Form_Load()
Dim s As Integer, M As Integer, H As Integer
len_s = Sqr((lineS.Y2 - lineS.Y1) ^ 2 + (lineS.X2 - lineS.X1) ^ 2)
len_M = Sqr((lineM.Y2 - lineM.Y1) ^ 2 + (lineM.X2 - lineM.X1) ^ 2)
len_H = Sqr((lineH.Y2 - lineH.Y1) ^ 2 + (lineH.X2 - lineH.X1) ^ 2)
Call Timer1_Timer
End Sub

Private Sub Timer1_Timer()
pi = 3.14159
t = Timer
Dim s As Integer, M As Integer, H As Integer, len_t As Integer
lineS.X2 = lineS.X1 + len_t * Sin(pi * Timer Mod 60 / 30)
lineS.Y2 = lineS.Y1 - len_t * Sin(pi * Timer Mod 60 / 30)
展开
 我来答
尘入蜓孟影食1038
推荐于2016-04-08 · TA获得超过3512个赞
知道大有可为答主
回答量:2307
采纳率:87%
帮助的人:1336万
展开全部
下面是全部代码
只要把这些复制到一个空白的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
AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
tn瓶邪
推荐于2016-12-05 · TA获得超过1881个赞
知道小有建树答主
回答量:610
采纳率:98%
帮助的人:112万
展开全部
复制到一个空白的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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
delo2134
2008-06-08 · 超过19用户采纳过TA的回答
知道答主
回答量:34
采纳率:0%
帮助的人:51.5万
展开全部
将下面的代码复制到文本文件里,再把扩展名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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
1149664344
2012-05-31 · TA获得超过654个赞
知道小有建树答主
回答量:184
采纳率:0%
帮助的人:34.3万
展开全部
建一个text 一个timer
在timer中写入代码:
text1.text=now
时间循环为100
ok
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式