3.4 events and interactivity
-
Upload
allenbailey -
Category
Technology
-
view
454 -
download
0
description
Transcript of 3.4 events and interactivity
Microsoft® Small Basic
Events and Interactivity
Estimated time to complete this lesson: 1 hour
Events and Interactivity
In this lesson, you will learn about:
Using keyboard events in your program.
Using mouse events in your program.
Introduction to Events
This lesson introduces you to events and controls with which you can add interactivity to your Small Basic programs.
In other words, you can create an interactive program in Small Basic by defining events that trigger an action in response to user inputs.
Interactivity here also includes control events that trigger an action on the click of a button or when some text is entered in a text box.
Keyboard Events
Keyboard events produce an action when a certain key is pressed. There are two keyboard events—KeyDown and KeyUp. These events are defined as operations of the GraphicsWindow object.
KeyDown raises an event when a key is pressed down on the keyboard.
KeyUp raises an event when a key is released on the keyboard.
Keyboard Events
Let’s demonstrate keyboard events in Small Basic with a simple program that allows you to rotate a shape on the graphics window by pressing a key on the keyboard.
In this example, you use the Return key on the keyboard to rotate a rectangle shape in the graphics window. When you press the Return key, the rectangle rotates, and on releasing the Return key, the rectangle returns to its original state.
Mouse Events
Like keyboard events, you can create programs in Small Basic that work with events based on mouse clicks. Mouse events generate actions in your program with the click of a mouse.
MouseDown raises an event when the mouse button is clicked.
MouseUp raises an event when the mouse button is released
MouseMove raises an event when the mouse is moved around in the graphics window.
Let’s see how we can use these events in a program.
Let’s Summarize…
Congratulations! Now you know how to:
Use keyboard events in your program.
Using mouse events in your program.
It’s Time to Apply Your Learning…
Write a program to demonstrate the Mouse events by performing the following steps:
Create a user interface with the help of the GraphicsWindow object.
Insert buttons to draw shapes with the help of the Controls object.
Use the MouseDown and MouseMove events to drop shapes in the drawing area.
Use If and Else statements to define the actions that take place by clicking the mouse.