Mouse Down Mouse Move Mouse Up Public Class

  • Slides: 4
Download presentation

滑鼠事件 (Mouse. Down, Mouse. Move, Mouse. Up) Public Class Form 1 Dim drag As

滑鼠事件 (Mouse. Down, Mouse. Move, Mouse. Up) Public Class Form 1 Dim drag As Boolean = False '宣告drag 變數, 用來記錄是否可拖曳 Private Sub Form 1_Load(By. Val sender As Object, By. Val e As System. Event. Args) Handles Me. Load 'Me. Text = "拖曳範例" ' Me. Background. Image = Image. From. File("c: /vb 2008/ch 10/image/Back. Image. jpg") ' pic. Black. Image = New Bitmap("c: /vb 2008/ch 10/image/black. gif") 'pic. Black. Size. Mode = Picture. Box. Size. Mode. Auto. Size 'pic. Black. Cursor = System. Windows. Forms. Cursors. Hand End Sub '按下滑鼠 Private Sub pic. Black_Mouse. Down(By. Val sender As Object, By. Val e As System. Windows. Forms. Mouse. Event. Args) Handles pic. Black. Mouse. Down If e. Button = Windows. Forms. Mouse. Buttons. Left Then '按下左鍵 drag = True End If End Sub '移動滑鼠 Private Sub pic. Black_Mouse. Move(By. Val sender As Object, By. Val e As System. Windows. Forms. Mouse. Event. Args) Handles pic. Black. Mouse. Move If drag Then pic. Black. Left += e. X pic. Black. Top += e. Y 'pic. Black. Left += e. X - pic. Black. Width / 2 'pic. Black. Top += e. Y - pic. Black. Height / 2 End If End Sub '放開滑鼠 Private Sub pic. Black_Mouse. Up(By. Val sender As Object, By. Val e As System. Windows. Forms. Mouse. Event. Args) Handles pic. Black. Mouse. Up drag = False End Sub End Class

滑鼠事件 (Mouse. Enter, Mouse. Hover, Mouse. Leave) Public Class Form 1 Private Sub Form

滑鼠事件 (Mouse. Enter, Mouse. Hover, Mouse. Leave) Public Class Form 1 Private Sub Form 1_Load(By. Val sender As Object, By. Val e As System. Event. Args) Handles Me. Load pic. Card. Image = Image. From. File("card. jpg") lbl. King. Text = "" End Sub '滑鼠進入時 Private Sub pic. Card_Mouse. Enter(By. Val sender As Object, By. Val e As System. Event. Args) Handles pic. Card. Mouse. Enter pic. Card. Image = Image. From. File("king. jpg") End Sub '滑鼠進入時且暫停時 Private Sub pic. Card_Mouse. Hover(By. Val sender As Object, By. Val e As System. Event. Args) Handles pic. Card. Mouse. Hover lbl. King. Text = "大家好!" + vb. Cr. Lf lbl. King. Text += "我是老K。K就是king,就是國王。" + vb. Cr. Lf lbl. King. Text += "很高興認識大家。" End Sub '滑鼠離開時 Private Sub pic. Card_Mouse. Leave(By. Val sender As Object, By. Val e As System. Event. Args) Handles pic. Card. Mouse. Leave pic. Card. Image = Image. From. File("card. jpg") lbl. King. Text = "" End Sub End Class

鍵盤事件(Key. Down, Key. Up) Public Class Form 1 Private Sub Form 1_Load(By. Val sender

鍵盤事件(Key. Down, Key. Up) Public Class Form 1 Private Sub Form 1_Load(By. Val sender As Object, By. Val e As System. Event. Args) Handles Me. Load pic. Rider. Image = Image. From. File("bike_go. jpg") End Sub Private Sub Form 1_Key. Down(By. Val sender As Object, By. Val e As System. Windows. Forms. Key. Event. Args) Handles My. Base. Key. Down lbl. Key. Text = "按下" & e. Key. Code. To. String() & "鍵, 鍵值為" & e. Key. Value 'Key. Value: 可以取得鍵盤值(ASCII code) 'Key. Code: 取得鍵盤碼 (eg: keys. Left, keys. F 1, keys. a, key. B, . . . ) If e. Key. Code = Keys. A Then pic. Rider. Image = Image. From. File("bike_go. jpg") If pic. Rider. Left >= Me. Width Then pic. Rider. Left = 0 - pic. Rider. Width Else pic. Rider. Left += 20 End If lbl. State. Text = " 前進!!" Else. If e. Key. Code = Keys. Left Then pic. Rider. Image = Image. From. File("bike_go. jpg") If pic. Rider. Width + pic. Rider. Left <= 0 Then pic. Rider. Left = Me. Width Else pic. Rider. Left -= 20 End If lbl. State. Text = " 後退!!" Else. If e. Key. Code = Keys. Up Then pic. Rider. Image = Image. From. File("bike_up. jpg") lbl. State. Text = " 舉孤輪!!" Else. If e. Key. Code = Keys. Down Then pic. Rider. Image = Image. From. File("bike_stop. jpg") lbl. State. Text = " 煞車!!" End If End Sub End Class