Presentation is loading. Please wait.

Presentation is loading. Please wait.

Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.

Similar presentations


Presentation on theme: "Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved."— Presentation transcript:

1 Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.

2 The Timer Control A control that enables you to generate response based on the value of the computer’s internal clock. Properties: Interval: Specify the frequency of timer events (measured in milliseconds = 1/1000 second). Enabled : False/True Events: Tick: The only event where you place the code for the timer control.

3 The Mouse The mouse is an object that is attached to the computer allowing the user to interact with the machine. The mouse can accomplish some tasks that are not normally available on the other.

4 The Mouse….Cont The mouse is equipped with: two, three, or more buttons. When a mouse has two buttons, one is usually located on the left and the other is located on the right. When a mouse has three buttons, one usually is in the middle of the other two. A mouse can also have a round object referred to as a wheel.

5 The Mouse….Cont The mouse is used to select a point or position on the screen. To use the mouse, the user would press either the left, the middle (if any), or the right button. If the user presses the left button once, this action is called Click. If the user presses the right mouse button, the action is referred to as Right-Click. If the user presses the left button twice and very fast, the action is called Double-Click. If the mouse is equipped with a wheel, the user can position the mouse pointer somewhere on the screen and roll the wheel. This usually causes the document or page to scroll up or down, slow or fast, depending on how it was configured.

6 Mouse Enter Event When positioninig the mouse on a control, the control fires a MouseEnter event. This event is initiated as follows: Private Sub ControlName_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseEnter This event let you know that the mouse was positioned on a control.

7 Mouse Move Event Whenever the mouse is being moved on top of a control, MouseMove event is sent. Private Sub Object_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove End Sub Tracking the mouse: e.X >>x position e.Y >> y position

8 Mouse Hover Event If the user positions the mouse on a control and hovers over it, a MouseHover event is fired. Private Sub Object_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseHover End Sub

9 Mouse Down Event Occurs when the user press down one of the mouse buttons while it is positioned on a control. Private Sub Object_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown End Sub Note: e.button (specify which button is clicked)

10 Mouse Up Event After pressing a mouse button, while the button is being released, a button-up message is sent. Private Sub Object_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp End Sub

11 Mouse Wheel Event If a mouse is equipped with a wheel, when the user presses the wheel or starts turning it, a MouseWheel event is fired. You can use this event to specify what would happen if or when the user decides to use the wheel. Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel End Sub

12 Mouse Leave Event When the user moves the mouse pointer away from a control, the control fires a MouseLeave event. Private Sub Form1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave End Sub

13 The Key Down Message When a keyboard key is pressed, a message called KeyDown is sent. Private Sub Object_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown End Sub To detect the key, use: e.Keydata or e.kayvalue

14 Key Press Event When the user presses a key, the KeyPress message is sent. Key pressed for this event should (must) be a character key. Private Sub Object_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress End Sub To detect the key you can use (e.keychar method)

15 Key Up Event KeyUp message is sent when the user releases the key. Private Sub Object_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp End Sub To detect the key, use: e.keydata e.keyvalue

16 Keyboard supprot Private Sub Button1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown MsgBox(e.KeyData) If e.KeyCode = Keys.A Then MsgBox("a") End If End Sub

17 Lab Training I Design a digital clock. Design an interface to move an object (button) in different directions as follow: 1.U : up 2.D : down 3.L : left 4.R : right 5.N : right diagonal 6.M : Left diagonal

18 End


Download ppt "Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved."

Similar presentations


Ads by Google