8
Microsoft® Small Basic Events and Interactivity Estimated time to complete this lesson: 1 hour

3.4 events and interactivity

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 3.4   events and interactivity

Microsoft® Small Basic

Events and Interactivity

Estimated time to complete this lesson: 1 hour

Page 2: 3.4   events and interactivity

Events and Interactivity

In this lesson, you will learn about:

Using keyboard events in your program.

Using mouse events in your program.

Page 3: 3.4   events and interactivity

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.

Page 4: 3.4   events and interactivity

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.

Page 5: 3.4   events and interactivity

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.

Page 6: 3.4   events and interactivity

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.

Page 7: 3.4   events and interactivity

Let’s Summarize…

Congratulations! Now you know how to:

Use keyboard events in your program.

Using mouse events in your program.

Page 8: 3.4   events and interactivity

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.