[Visual Basic 6.0] TQC 企業人才技能認證 Visual Basic 程式設計 - 402 滑鼠事件管理

摘要:[Visual Basic 6.0] TQC 企業人才技能認證 Visual Basic 程式設計 - 402 滑鼠事件管理

[Visual Basic 6.0] TQC 企業人才技能認證 Visual Basic 程式設計 - 402 滑鼠事件管理


Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single) ' 當表單上有物件移動位置時
Source.Move (X - Source.Width / 2), (Y - Source.Height / 2) ' 背下來
lblThing(Source.Index).Move (Source.Left + 500), (Source.Top) ' 背下來
End Sub

Private Sub Form_Load()
    picTrashCan(0).Visible = False    '設為隱藏
    picTrashCan(1).Visible = False  '設為隱藏
    picTrashCan(2).Visible = False  '設為隱藏
    picTrashCan(3).Visible = False  '設為隱藏
    picState.Picture = picTrashCan(0).Picture ' 一開始是 空的 沒有蓋蓋子
End Sub

Private Sub picState_DblClick() ' picState 滑鼠雙點時的事件 (焚燒)
picState.Picture = picTrashCan(3).Picture ' 一開始變成 焚燒的畫面
'延遲 N 秒

For i = 1 To 100000
    DoEvents
Next i

MsgBox "已焚燒的垃圾為:" & vbCrLf & vbCrLf & Me.Tag, , "垃圾桶" ' 跳出視窗 因為我是用 Form1 的 Tag 存資料 (Me = Form)
Me.Tag = "" ' 焚燒後清空 存下的資料
picState.Picture = picTrashCan(0).Picture ' 變成空的沒有蓋蓋子
End Sub

Private Sub picState_DragDrop(Source As Control, X As Single, Y As Single) ' 當 物件 移動到 picState 的上面放開時 (丟到垃圾桶)
'Source.Index = 目前選到的圖片 Index 值
Me.Tag = Me.Tag & lblThing(Source.Index).Caption & vbCrLf ' 把 刪除的資料 放入 Tag 中 ( lblThing(Source.Index).Caption 是 Label 的裡面的字 )
' lblThing(0).Caption = "資料夾" ,  lblThing(1).Caption = "文件" ...等等
lblThing(Source.Index).Visible = False ' 隱藏 Label
picThing(Source.Index).Visible = False ' 隱藏 圖示
picState.Picture = picTrashCan(2).Picture ' 垃圾桶圖片改變成 第 2 張 為 => 有垃圾的垃圾桶的圖示
End Sub

Private Sub picState_DragOver(Source As Control, X As Single, Y As Single, State As Integer) ' 當 有物件移動到 垃圾桶附近的時候
Select Case State ' 判斷 State 值
    Case 0 ' State = 0 的時候為 當 有物件 移動到接近 picState 物件的時候
        picState.Picture = picTrashCan(1).Picture ' 打開蓋子且垃圾桶內變成有垃圾的狀態
    Case 1 ' State = 1 的時候為 當 有物件 從 PicState 物件移走的時候
        picState.Picture = picTrashCan(2).Picture ' 蓋子蓋上
End Select
End Sub

402 詳細講義.rar

#0xDe 從分享中學習

#Facebook:ProgrammerDe (https://www.facebook.com/MicrosoftDes) 有問題歡迎提問