An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
螢幕保護程式 第一版Step 4 • 在 Form_KeyDown 事件程序中撰寫以下程式: • 當程式偵測到使用者按下鍵盤時,即呼叫 Unload Me 載出表單。 Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Unload Me ' 載出表單End Sub
螢幕保護程式 第一版Step 6 • 在 Form_MouseMove 事件程序中撰寫以下程式: • 以上程式在偵測到滑鼠移動時,也一樣呼叫 Unload Me 載出表單結束程式。 Dim X0 As Single, Y0 As Single ' 用來記錄滑鼠的位置Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) ' 第一次發生滑鼠事件時,將位置記錄於 (X0,Y0) If X0 = 0 And Y0 = 0 Then X0 = X: Y0 = Y ' 如果滑鼠位置改變,就載出表單If X <> X0 Or Y <> Y0 Then Unload MeEnd Sub
改良程式 -- Part I (1) • 因此為了改變螢幕保護程式第一版的缺點,筆者在 Form_Load 事件程序中(會在表單被載入時被執行)撰寫以下程式:
改良程式 -- Part I (2) Private Sub Form_Load() If UCase(Left(Command, 2)) = "/A" Then ' 密碼設定MsgBox "此一螢幕保護程式未提供「密碼保護」功能!"Unload Me End If If UCase(Left(Command, 2)) = "/C" Then ' 設定值MsgBox "此一螢幕保護程式沒有「設定值」!"Unload Me End If If UCase(Left(Command, 2)) = "/P" Then ' 小螢幕Unload Me End If…End Sub
改良程式 -- Part II Private Sub Form_Load() If UCase(Left(Command, 2)) = "/A" Then ' 密碼設定MsgBox "此一螢幕保護程式未提供「密碼保護」功能!"Unload Me End If If UCase(Left(Command, 2)) = "/C" Then ' 設定值MsgBox "此一螢幕保護程式沒有「設定值」!"Unload Me End If If UCase(Left(Command, 2)) = "/P" Then ' 小螢幕Unload Me End If If App.PrevInstance Then ' 已經在執行中Unload Me End IfEnd Sub • 在 Form_Load 件程序的最後面增加了以下敘述:
反彈球 -- Step 3-1 • 更改 Timer1_Timer 事件程序的內容: Dim X0 As Single, Y0 As Single ' 這是既有的敘述Dim Motion As Integer ' 這是新增的敘述Private Sub Timer1_Timer() Dim offset As Integer If Motion = 0 Then Motion = 3 offset = Image1.Width \ 10
反彈球 -- Step 3-2 Select Case Motion Case 1 ' 向左上角移動Image1.Move Image1.Left - offset, Image1.Top - offset If Image1.Left <= 0 Then Motion = 2 ElseIf Image1.Top <= 0 Then Motion = 4 End If Case 2 ' 向右上角移動Image1.Move Image1.Left + offset, Image1.Top - offset If Image1.Left >= (Form1.ScaleWidth - Image1.Width) Then Motion = 1 ElseIf Image1.Top <= 0 Then Motion = 3 End If
反彈球 -- Step 3-3 Case 3 ' 向右下角移動Image1.Move Image1.Left + offset, Image1.Top + offset If Image1.Left >= (Form1.ScaleWidth - Image1.Width) Then Motion = 4 ElseIf Image1.Top >= (Form1.ScaleHeight - Image1.Height) Then Motion = 2 End If Case 4 ' 向左下角移動Image1.Move Image1.Left - offset, Image1.Top + offset If Image1.Left <= 0 Then Motion = 3 ElseIf Image1.Top >= (Form1.ScaleHeight - Image1.Height) Then Motion = 1 End If End SelectEnd Sub
月有陰晴圓缺 -- Step 2-1 2. 修改 Timer1_Timer 事件程序的程式: Dim X0 As Single, Y0 As SingleDim Motion As IntegerDim Index As Integer ' 新增Private Sub Timer1_Timer() Set Image1.Picture = Image2(Index).Picture ' 新增 Dim offset As Integer If Motion = 0 Then Motion = 3 offset = Image1.Width \ 10 Select Case Motion
月有陰晴圓缺 -- Step 2~2 Case 1 ' 向左上角移動Image1.Move Image1.Left - offset, Image1.Top - offset If Image1.Left <= 0 Then Motion = 2 ElseIf Image1.Top <= 0 Then Motion = 4 End IfCase 2 ' 向右上角移動Image1.Move Image1.Left + offset, Image1.Top - offset If Image1.Left >= (Form1.ScaleWidth - Image1.Width) Then Motion = 1 ElseIf Image1.Top <= 0 Then Motion = 3 End If
月有陰晴圓缺 -- Step 2~3 Case 3 ' 向右下角移動Image1.Move Image1.Left + offset, Image1.Top + offset If Image1.Left >= (Form1.ScaleWidth - Image1.Width) Then Motion = 4 ElseIf Image1.Top >= (Form1.ScaleHeight - Image1.Height) Then Motion = 2 End If
月有陰晴圓缺 -- Step 2~4 Case 4 ' 向左下角移動Image1.Move Image1.Left - offset, Image1.Top + offset If Image1.Left <= 0 Then Motion = 3 ElseIf Image1.Top >= (Form1.ScaleHeight - Image1.Height) Then Motion = 1 End If End Select Index = Index + 1 ' 新增If Index = 8 Then Index = 0 ' 新增End Sub