| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 710 人关注过本帖
标题:关于VB时钟移动的问题
只看楼主 加入收藏
ken6o
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-6-28
收藏
 问题点数:0 回复次数:2 
关于VB时钟移动的问题
要做一个时钟
请教怎么利用键盘的方向上下来移动修改时间





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
搜索更多相关主题的帖子: 时钟 
2008-12-11 10:51
我是菜鸟哦
Rank: 6Rank: 6
等 级:贵宾
威 望:22
帖 子:921
专家分:209
注 册:2007-5-4
收藏
得分:0 
用FORM的KEYDOWN事件

偶是菜鸟鸟偶惧WHO?!!!!
2008-12-11 11:28
三断笛
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:31
帖 子:1621
专家分:1617
注 册:2007-5-24
收藏
得分:0 
用DTPick控件
2008-12-11 13:36
快速回复:关于VB时钟移动的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017205 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved