在VB中,做一个指针式时钟,什么代码?最好有注释的

 我来答
匿名用户
2013-11-15
展开全部
'在窗体中添加一个Timer控件,将Interval设为1000以下。
'////////////////////////////////
Option ExplicitConst PI = 3.1415926
Dim BaseX As Integer, BaseY As Integer, R As Integer
Dim r1 As Integer, r2 As Integer, r3 As IntegerPrivate Sub Form_Load()
Me.ScaleMode = 3
Me.AutoRedraw = True

If Me.Width < 3000 Then Me.Width = 3000
If Me.Height < 3000 Then Me.Height = 3000

End SubPrivate Sub Init()
Dim i As Integer BaseX = Me.ScaleWidth / 2
BaseY = Me.ScaleHeight / 2

R = IIf(BaseX > BaseY, BaseY * 0.8, BaseY * 0.8)
r1 = R * 0.2
r2 = R * 0.1
r3 = R * 0.05 For i = 0 To 360 Step 6

If i Mod 30 = 0 Then '时
Me.DrawWidth = 2
DrawLine BaseX + (R - 3) * Sin(i * PI / 180), BaseY - (R - 3) * Cos(i * PI / 180), BaseX + (R - 8) * Sin(i * PI / 180), BaseY - (R - 8) * Cos(i * PI / 180), 3
Else '分
Me.DrawWidth = 2
Me.PSet (BaseX + (R - 3) * Sin(i * PI / 180), BaseY - (R - 3) * Cos(i * PI / 180))
End If
Next

Me.DrawWidth = 1
Me.Circle (BaseX, BaseY), R
End Sub'绘制指针
Private Sub DrawClock()
Dim Second As Integer
Dim Minute As Integer
Dim Hours As Integer Second = DatePart("s", Time)
Minute = DatePart("n", Time)
Hours = DatePart("h", Time)
If Hours > 12 Then
Hours = Hours - 12
End If Me.DrawWidth = 1
Me.Circle (BaseX, BaseY), 4 DrawLine BaseX - r1 * Sin(Second * PI / 30), BaseY + r1 * Cos(Second * PI / 30), BaseX + (R - 10) * Sin(Second * PI / 30), BaseY - (R - 10) * Cos(Second * PI / 30), 0
DrawLine BaseX - r2 * Sin(Minute * PI / 30), BaseY + r2 * Cos(Minute * PI / 30), BaseX + R * 0.8 * Sin(Minute * PI / 30), BaseY - R * 0.8 * Cos(Minute * PI / 30), 1
DrawLine BaseX - r3 * Sin((Hours + Minute / 60) * PI / 6), BaseY + r3 * Cos((Hours + Minute / 60) * PI / 6), BaseX + R * 0.6 * Sin((Hours + Minute / 60) * PI / 6), BaseY - R * 0.6 * Cos((Hours + Minute / 60) * PI / 6), 2
End Sub'画线函数
Private Sub DrawLine(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, Flag As Integer)
Static OldSX1 As Integer, OldSX2 As Integer, OldSY1 As Integer, OldSY2 As Integer
Static OldMX1 As Integer, OldMX2 As Integer, OldMY1 As Integer, OldMY2 As Integer
Static OldHX1 As Integer, OldHX2 As Integer, OldHY1 As Integer, OldHY2 As Integer
Select Case Flag
Case 0
Me.DrawWidth = 1
Me.Line (OldSX1, OldSY1)-(OldSX2, OldSY2), Me.BackColor
Me.Line (x1, y1)-(x2, y2)
OldSX1 = x1
OldSX2 = x2
OldSY1 = y1
OldSY2 = y2
Case 1
Me.DrawWidth = 2
Me.Line (OldMX1, OldMY1)-(OldMX2, OldMY2), Me.BackColor
Me.Line (x1, y1)-(x2, y2)
OldMX1 = x1
OldMX2 = x2
OldMY1 = y1
OldMY2 = y2
Case 2
Me.DrawWidth = 3
Me.Line (OldHX1, OldHY1)-(OldHX2, OldHY2), Me.BackColor
Me.Line (x1, y1)-(x2, y2)
OldHX1 = x1
OldHX2 = x2
OldHY1 = y1
OldHY2 = y2
Case Else
Me.Line (x1, y1)-(x2, y2)
End Select
End SubPrivate Sub Form_Resize()
Me.Cls
Call Init
End SubPrivate Sub Timer1_Timer()
Call DrawClock
End Sub
稍微注释了一下,觉得太简单 没必要注释,在说这是我自己以前无聊的时候写的,你要实在不明白就按F8慢慢看咯。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-11-15
展开全部
从部件中填加时间控件,做计时用,然后画时钟外形,用select case语句和line画线语句对不同特殊时刻编程
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式