Top Banner
Microsoft® Small Basic The Controls Object Estimated time to complete this lesson: 1 hour
12
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 3.5   the controls object

Microsoft® Small Basic

The Controls Object

Estimated time to complete this lesson: 1 hour

Page 2: 3.5   the controls object

The Controls Object

In this lesson, you will learn about:

Using various properties of the Controls object.

Using various operations of the Controls object.

Using control events on buttons and text boxes in your program.

Page 3: 3.5   the controls object

Introduction to the Controls Object

So far, you have learned to use different objects in Small Basic, such as the GraphicsWindow, Shapes, File, and Math objects.

This lesson introduces you to the Controls object offered by Small Basic. Using the Controls object, you can insert simple controls like text boxes and buttons in the graphics window.

Page 4: 3.5   the controls object

Operations of the Controls Object

Before we move on and create a program by using the Controls object, let’s learn about some operations of the Controls object along with their parameters.

AddTextBox—You can use this operation to add a text box to the graphics window. You must specify the x- and y-coordinates of the text box as parameters.

AddButton—You can use this operation to add a button in the graphics window. You must specify the caption of the button and its x- and y-coordinates as parameters.

Page 5: 3.5   the controls object

Operations of the Controls Object

GetButtonCaption—With this operation, you can retrieve the caption of a button. You must specify the appropriate button name as a parameter.

SetButtonCaption—With this operation, you can set or change the caption of a button. You must specify the button name and the new caption as parameters.

GetTextBoxText—You can retrieve the text present in a specified text box by specifying the text box name as a parameter for this operation.

SetTextBoxText—You can define the text to appear in a text box. You must specify the name of the text box and the required text as parameters.

Page 6: 3.5   the controls object

Operations of the Controls Object

Along with being able to add useful controls into your program, you can perform certain operations and define the settings for the controls you add.

Let’s explore the Controls object with the help of an example.

Page 7: 3.5   the controls object

Properties and Operations of the Controls object

Let’s look at the capabilities offered by a few more operations and properties of the Controls object.

HideControl—You can use this operation to hide an existing control from the graphics window.ShowControl—This operation allows you to display a previously hidden control on the graphics window.Remove—You can use this operation to remove a control from the graphics window.

Page 8: 3.5   the controls object

Properties and Operations of the Controls object

SetSize—You can use this operation to specify a fixed size for a control. You must specify the control name and the height and width of the control as parameters.

Move—You can use this operation to move a control to a new position in the graphics window. You must specify the control name as well as the height and width of the control as parameters.

LastClickedButton—You can use this operation to find the last button that was clicked on the graphics window.

LastTypedTextBox—You can use this operation to find the last text box where text was typed.

Page 9: 3.5   the controls object

The Controls Object

Now let’s write a simple program by using the Controls object. This program can be used to display the definitions of a given word.

OUTPUT

Page 10: 3.5   the controls object

Control Events

Now that you are familiar with the Controls object in Small Basic, let’s get acquainted with the events that you can use for the Controls object. Control events can generate actions in your program when a button is clicked or some text is typed into a text box.

ButtonClicked raises an event when a button control is clicked.

TextTyped raises an event when text is typed into a textbox control.

You can use the ButtonClicked event to make a simple calculator as shown to the right:

And here’s an example of the TextTyped event:

Page 11: 3.5   the controls object

Let’s Summarize…

Congratulations! Now you know how to:

Use various properties of the Controls object.

Use various operations of the Controls object.

Use control events on buttons and text boxes in your program.

Page 12: 3.5   the controls object

It’s Time to Apply Your Learning…

Write a program to display a simple form, and perform the following steps:

Add text boxes to accept the name, address, telephone number, and e-mail address of the user.

Add a Submit button to the form.

When information is entered in all the text boxes and the Submit button is clicked, display an appropriate message.