小制作- -炫彩水晶钟 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 Longx = 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 Form2Frame = ((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, opcodex1,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 Form3Frame = 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 WithGoTo siga '進行秒針的判斷、載入,優化程序,提高效率。End If If minutos > 14 And minutos < 30 Then '優化查找指針。minutos = minutos - 15With Form3Frame = 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 / 15End WithGoTo sigaEnd If If minutos > 29 And minutos < 45 Thenminutos = minutos - 30 '產生的總是0~14 間的數With Form3Frame = 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 / 15End WithGoTo sigaEnd If If minutos > 44 Thenminutos = minutos - 45With Form3Frame = 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 / 15End WithEnd If siga: '具體判斷秒針載入If segundos < 15 ThenWith Form4Frame = 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 / 15End WithGoTo fimEnd IfIf segundos > 14 And segundos < 30 Thensegundos = segundos - 15With Form4Frame = 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 / 15End WithGoTo fimEnd IfIf segundos > 29 And segundos < 45 Thensegundos = segundos - 30With Form4Frame = 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 / 15End WithGoTo fimEnd IfIf segundos > 44 Thensegundos = segundos - 45With Form4Frame = 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 / 15End WithEnd Iffim: '為空,已完成了對時間指針的加載過程,如是就直接跳轉到End Sub。End Sub
?
?
?
?
?
表盤圖
?
?
?
指針圖
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的小制作- -炫彩水晶钟 TOM搬家的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 这个程序员火了,竟是因为给老板修了一 次
- 下一篇: 国密算法SM4加密,数据加密存储加密