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 In other words, you can create an interactive program in Small Basic by defining events that trigger an action in response to user inputs. This lesson introduces you to events and controls with which you can add interactivity to your Small Basic programs. 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—KeyDownand KeyUp. These events are defined as operations of the GraphicsWindow object. KeyUp raises an event when a key is released on the keyboard. KeyDown raises an event when a key is pressed down 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 Let’s see how we can use these events in a program. MouseDown raises an event when the mouse button is clicked. MouseUp raises an event when the mouse button is released 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. MouseMove raises an event when the mouse is moved around in the graphics window.
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.