小制作- -炫彩水晶钟 TOM搬家

2009-05-02 12:50:59 分类:提高班学习

为了牛人展示,我们也算是好好练练手哈~ 小兵主刀的,“超酷超炫石英钟”,很好很大。

可是在如何判断加载指针问题上卡壳了,可是如此难题经我**了哈~

如是,我就有了如下的总结哈~

(由于水平有限,恐有解释不到、错误之处,还请大家不吝斧正~)

这部分的构思在整个程序来说有着举足轻重的作用,下面我们来**一下如何据实载入表盘指针。

form1/form2/form3/form4 分别为主窗体、时针窗体、分针窗体、秒针窗体。

Form2.Picture1.Picture = LoadPicture(App.Path & "PH.bmp") '前期读入时针图像

下面代码实现的是如何具体地载入时、分、秒表盘指针的操作:

Private Sub Timer1_Timer() Static hora As Integer, minutos As Integer, segundos As Integer, x As String, Frame As Long x = Format(Now, "hh:mm:ss") '格式化当前时间 hora = Val(Mid$(x, 1, 2)) Mod 12 '产生0~11 的数字 minutos = Val(Mid$(x, 4, 2)) '读取相应的分 segundos = Val(Mid$(x, 7, 2)) '读取相应的秒 With Form2 Frame = ((hora Mod 12) * 2 - (minutos > 30)) * ((.Picture1.Height / 24)) '分析可知表盘时针所在的PH.bmp图像*有24个指针,分别对应0~23;而其中(minutos>30)是bolloean 类型,只有0和1值;由于原来的12 个对应于现在的24个,所以有(hora Mod 12 )* 2;在(Picture1.Height/24)是说将PH.bmp图像均分为24分,也就是每个表盘时针是等大的分开的,排列为一队,这就有点那个数组的意思哈~~~ 那么整个的Frame也就是表示的现在系统时间相对应的那个指针在PH.bmp中的位置/高度。 .Picture2.PaintPicture .Picture1,0,0, .Picture1.Width, .Picture1.Height / 24, 0, Frame, .Picture1.Width, .Picture1.Height / 24 '具体需要解决的问题是paintpicture如何使用:object.PaintPicture picture, x1, y1, width1, height1, x2, y2, width2, height2, opcode x1,y1 :指的是object上绘制picture1的目标坐标,也就是实例中的picture2上画复制picture1的坐标点,说白了也就是picture2里的东西放到picture1的位置坐标。 width1,height1:指的就是宽、高,也就是大小了。就是提前在picture1上圈定一个范围用来放picture2的东西。 x2,y2:也就是裁剪区的坐标,说白了是,裁剪的坐标始点,那么裁剪就是从这里开始的,而不是到这里为止。 width2,height2:对应的就是源裁剪区,也就是你要裁取的大小范围。 那么这里的 0,Frame 就是对应到了 HP.bmp 时针表针图像里具体哪个表针的位置了。如此而已,超赞视觉效果的表针就算是从图像中加载成功了。 End With '分针图像由四个.bmp图像组成。60个分针指针由picture1(0)、picture1(1)、picture1(2)picture1(3)分别承载。 If minutos < 15 Then 'minutos是一个0~14的数 With Form3 Frame = minutos * (.Picture1(0).Height / 15) .Picture2.PaintPicture .Picture1(0), 0, 0, .Picture1(0).Width, .Picture1(0).Height / 15, 0, Frame, .Picture1(0).Width, .Picture1(0).Height / 15 '同以上时针的载入分析。 End With GoTo siga '进行秒针的判断、载入,优化程序,提高效率。 End If If minutos > 14 And minutos < 30 Then '优化查找指针。 minutos = minutos - 15 With Form3 Frame = minutos * (Form3.Picture1(1).Height / 15) .Picture2.PaintPicture Form3.Picture1(1), 0, 0, Form3.Picture1(1).Width, Form3.Picture1(1).Height / 15, 0, Frame, Form3.Picture1(1).Width, Form3.Picture1(1).Height / 15 End With GoTo siga End If If minutos > 29 And minutos < 45 Then minutos = minutos - 30 '产生的总是0~14 间的数 With Form3 Frame = minutos * (.Picture1(2).Height / 15) .Picture2.PaintPicture .Picture1(2), 0, 0, .Picture1(2).Width, .Picture1(2).Height / 15, 0, Frame, .Picture1(2).Width, .Picture1(2).Height / 15 End With GoTo siga End If If minutos > 44 Then minutos = minutos - 45 With Form3 Frame = minutos * (.Picture1(3).Height / 15) .Picture2.PaintPicture .Picture1(3), 0, 0, .Picture1(3).Width, .Picture1(3).Height / 15, 0, Frame, .Picture1(3).Width, .Picture1(3).Height / 15 End With End If siga: '具体判断秒针载入 If segundos < 15 Then With Form4 Frame = segundos * (.Picture1(0).Height / 15) .Picture2.PaintPicture .Picture1(0), 0, 0, .Picture1(0).Width, .Picture1(0).Height / 15, 0, Frame, .Picture1(0).Width, .Picture1(0).Height / 15 End With GoTo fim End If If segundos > 14 And segundos < 30 Then segundos = segundos - 15 With Form4 Frame = segundos * (.Picture1(1).Height / 15) .Picture2.PaintPicture .Picture1(1), 0, 0, .Picture1(1).Width, .Picture1(1).Height / 15, 0, Frame, .Picture1(1).Width, .Picture1(1).Height / 15 End With GoTo fim End If If segundos > 29 And segundos < 45 Then segundos = segundos - 30 With Form4 Frame = segundos * (.Picture1(2).Height / 15) .Picture2.PaintPicture .Picture1(2), 0, 0, .Picture1(2).Width, .Picture1(2).Height / 15, 0, Frame, .Picture1(2).Width, .Picture1(2).Height / 15 End With GoTo fim End If If segundos > 44 Then segundos = segundos - 45 With Form4 Frame = segundos * (.Picture1(3).Height / 15) .Picture2.PaintPicture .Picture1(3), 0, 0, .Picture1(3).Width, .Picture1(3).Height / 15, 0, Frame, .Picture1(3).Width, .Picture1(3).Height / 15 End With End If fim: '为空,已完成了对时间指针的加载过程,如是就直接跳转到End Sub。 End Sub

表盘图

小制作- -炫彩水晶钟 TOM搬家

指针图

小制作- -炫彩水晶钟 TOM搬家