vb数字时钟代码(vb制作时钟)
admin 发布:2022-12-19 23:51 165
今天给各位分享vb数字时钟代码的知识,其中也会对vb制作时钟进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、vb中设置一个数字时钟界面,每改变一秒就更新一次,求程序。
- 2、VB编辑计时器显示当前时间的数字时钟(包括时:分:秒)代码
- 3、怎么用VB来制作时钟
- 4、vb 时钟代码
- 5、用VB编写一个钟表的代码是?
- 6、vb中怎样做出时钟?
vb中设置一个数字时钟界面,每改变一秒就更新一次,求程序。
Private Sub Form_Load()
Me.Caption = "数字时钟"
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Format(Now, "yyyy年m月d日")
Label2.Caption = Format(Now, "hh时nn分ss秒")
End Sub
VB编辑计时器显示当前时间的数字时钟(包括时:分:秒)代码
Private
Sub
Form_Load()
Timer1.Enabled
=
True
Timer1.Interval
=
1000
Label1.Caption
=
Time$
'在Form_Load就要加上,否则你要等1秒后Label才会开始跑
End
Sub
Private
Sub
Timer1_Timer()
Label1.Caption
=
Time$
End
Sub
怎么用VB来制作时钟
下面是全部代码
只要把这些复制到一个空白的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
vb 时钟代码
Private
Sub
Form_Load()
Form1.AutoRedraw
=
True
Form1.Height
=
3500
Form1.Width
=
3500
Form1.Scale
(-100,
100)-(100,
-100)
'这里VB是以正X和负Y开始原始坐标,就是Y坐标和我们平时画的相反
Line1.X1
=
0:
Line1.Y1
=
Line2.X1
=
0:
Line2.Y1
=
Line3.X1
=
0:
Line3.Y1
=
Line1.BorderColor
=
RGB(0,
0,
0)
Line1.BorderWidth
=
3
Line2.BorderColor
=
RGB(0,
0,
255)
Line2.BorderWidth
=
2
Line3.BorderColor
=
RGB(255,
0,
0)
Shape1.Top
=
95
'这里因为Y坐标是相反的,所以要正数
Shape1.Left
=
-95
Line3.BorderWidth
=
1
Shape1.BorderStyle
=
3
Shape1.BorderWidth
=
3
Shape1.Width
=
190
Shape1.Height
=
190
Shape1.BorderColor
=
RGB(0,
0,
255)
Timer1.Interval
=
1000
End
Sub
Private
Sub
Timer1_Timer()
sx
=
Cos((180
-
6
*
Second(Time))
*
3.14159
/
180)
*
65
'COS。不知道怎么说
sy
=
Sin((180
-
6
*
Second(Time))
*
3.14159
/
180)
*
65
'同上,的秒针反方向转了
Line3.X2
=
sx
Line3.Y2
=
sy
mx
=
Cos((180
-
6
*
Minute(Time))
*
3.14159
/
180)
*
65
my
=
Sin((180
-
6
*
Minute(Time))
*
3.14159
/
180)
*
65
Line2.X2
=
mx
Line2.Y2
=
my
hx
=
Cos((180
-
(30
*
Hour(Time)
+
30
*
Minute(Time)
/
60))
*
3.14159
/
180)
*
40
hy
=
Sin((180
-
(30
*
Hour(Time)
+
30
*
Minute(Time)
/
60))
*
3.14159
/
180)
*
40
Line1.X2
=
hx
Line1.Y2
=
hy
Form1.CurrentX
=
-2
Form1.CurrentY
=
80
Form1.Print
"12"
Form1.CurrentX
=
75
Form1.CurrentY
=
-8
Form1.Print
"3"
Form1.CurrentX
=
-80
Form1.CurrentY
=
-8
Form1.Print
"9"
End
Sub
用VB编写一个钟表的代码是?
Private Sub Command1_Click()
End Sub
Private Sub Check1_Click()
If Check1.Value = 0 Then
Timer1.Enabled = False
Check1.Caption = "钟表已停"
Else
Timer1.Enabled = True
Check1.Caption = "钟表正在走动"
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 0 Then
Label1.Visible = False
Check2.Caption = "钟表已关闭"
Else
Label1.Visible = True
Check2.Caption = "钟表已打开"
End If
End Sub
Private Sub Form_Load()
Label1.Caption = Time
End Sub
Private Sub HScroll1_Change()
Label1.ForeColor = RGB(Int(HScroll3.Value), Int(HScroll2.Value), Int(HScroll1.Value))
End Sub
Private Sub HScroll2_Change()
Label1.ForeColor = RGB(Int(HScroll3.Value), Int(HScroll2.Value), Int(HScroll1.Value))
End Sub
Private Sub HScroll3_Change()
Label1.ForeColor = RGB(Int(HScroll3.Value), Int(HScroll2.Value), Int(HScroll1.Value))
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Time
End Sub
Private Sub Timer2_Timer()
Dim i, j, k As Integer
i = Int(Rnd() * 225 + 1) + 0
j = Int(Rnd() * 225 + 1) + 0
k = Int(Rnd() * 225 + 1) + 0
Label1.BackColor = RGB(i, j, k)
End Sub
vb中怎样做出时钟?
VB可使用Timer控件、Line控件和绘图或加载图片等制作指针式时钟。
Timer 控件,通过引发 Timer 事件,Timer 控件可以有规律地隔一段时间执行一次代码。
Line 控件,Line 控件是图形控件,它显示水平线、垂直线或者对角线。
运行时不能使用 Move 方法移动 Line 控件,但是可以通过改变 X1、X2、Y1 和 Y2
属性来移动它或者调整它的大小。
Circle 方法,在对象上画圆、椭圆或弧。
以下是通过加载图片的指针式时钟代码:
Option Explicit
Private Const PI = 3.1415926
Dim X(1) As Single, Y(1) As Single
Dim OriAngle As Single, DestAngle As Single, r As Single
Private Sub RotateLine(objL As Line, bsPointX As Single, bsPointY As Single, RotateAngle As Single)
With objL
X(0) = .X1
Y(0) = .Y1
X(1) = .X2
Y(1) = .Y2
End With
Dim i As Integer
For i = 0 To 1
If X(i) - bsPointX 0 Then
OriAngle = Atn((Y(i) - bsPointY) / (X(i) - bsPointX))
Else
OriAngle = IIf(Y(i) bsPointY, PI / 2, 1.5 * PI)
End If
If X(i) - bsPointX 0 Then
If OriAngle 0 Then
OriAngle = PI - Abs(OriAngle)
Else
OriAngle = PI + Abs(OriAngle)
End If
End If
DestAngle = OriAngle + RotateAngle
r = Sqr((X(i) - bsPointX) ^ 2 + (Y(i) - bsPointY) ^ 2)
X(i) = bsPointX + r * Cos(DestAngle)
Y(i) = bsPointY + r * Sin(DestAngle)
Next i
With objL
.X1 = X(0)
.Y1 = Y(0)
.X2 = X(1)
.Y2 = Y(1)
End With
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Dim i As Long
For i = 1 To Val(Mid(Time$, 7, 2))
RotateLine Line3, Line3.X1, Line3.Y1, 1 * PI / 30
Next
For i = 1 To Val(Mid(Time$, 4, 2))
RotateLine Line2, Line2.X1, Line2.Y1, 1 * PI / 30
Next
For i = 1 To Val(Mid(Time$, 1, 2)) * 5 '对时针
RotateLine Line1, Line1.X1, Line1.Y1, 1 * PI / 30
Next
For i = 1 To Val(Mid(Time$, 4, 2)) '对时针
RotateLine Line1, Line1.X1, Line1.Y1, 1 * PI / 360
Next
End Sub
Private Sub Timer1_Timer()
RotateLine Line3, Line3.X1, Line3.Y1, 1 * PI / 30
RotateLine Line2, Line2.X1, Line2.Y1, PI / 1800
If Mid(Time$, 7, 2) = "00" Or Mid(Time$, 7, 2) = "30" Then
RotateLine Line1, Line1.X1, Line1.Y1, 1 * PI / 720
End If
Me.Caption = Time$
End Sub
vb数字时钟代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb制作时钟、vb数字时钟代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:描文本代码(描文本什么意思)
- 下一篇:网站漂浮qq代码(网站跳转代码)
相关推荐
- 05-18重庆网站建设,重庆网站建设与制作
- 05-18网站设计与制作,网站设计与制作毕业论文范文
- 05-18制作网页一般多少钱,网页制作要多少钱
- 05-17怎么制作网址,怎么制作网址二维码
- 05-17个人网页设计作品模板,个人网页设计与制作模板
- 05-15如何制作一个网页网站,如何制作一个网页?
- 05-15广西网站建设制作,广西网站建设制作公司
- 05-15免费开发软件制作平台,软件免费开发网站
- 05-14网站建设网站制作,网站建设制作免费
- 05-13怎么制作公司网页,怎样制作自己公司的网页
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接