Microsoft® Small Basic<br />The Controls Object<br />Estimated time to complete this lesson: 1 hour<br />
The Controls Object<br />In this lesson, you will learn about:<br />Using various properties of the Controls object.<br />...
Introduction to the Controls Object<br />This lesson introduces you to the Controls object offered by Small Basic. Using t...
Operations of the Controls Object<br />Before we move on and create a program by using the Controls object, let’s learn ab...
Operations of the Controls Object<br />GetButtonCaption—With this operation, you can retrieve the caption of a button. You...
 Operations of the Controls Object<br />Along with being able to add useful controls into your program, you can perform ce...
Properties and Operations of the Controls object<br />Let’s look at the capabilities offered by a few more operations and ...
Properties and Operations of the Controls object<br />SetSize—You can use this operation to specify a fixed size for a con...
The Controls Object<br />Now let’s write a simple program by using the Controls object. This program can be used to displa...
Control  Events<br />Now that you are familiar with the Controls object in Small Basic, let’s get acquainted with the even...
Let’s Summarize…<br />Congratulations! Now you know how to:<br />Usevarious properties of the Controls object.<br />Use va...
It’s Time to Apply Your Learning…<br />Write a program to display a simple form, and perform the following steps:<br /><ul...
Upcoming SlideShare
Loading in...5
×

3.5 the controls object

760

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
760
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Code:textbox = Controls.AddTextBox(200, 150)button = Controls.AddButton(“Button”, 150, 200)
  • Notes:You can add controls onto the screen by typing a statement containing the Controls object with a suitable operation. Take a look at the example on the screen:First, you use the AddTextBoxoperation of the Controls object to add text boxes that accept the name of the user. You need to specify the x- and y-coordinates of the text boxes as parameters. Next, you use the AddButtonoperation to add a button onto the graphics window. Apart from the x- and y-coordinates, you must also specify the button caption as a parameter. Next, you use the AddMultiLineTextBox operation to add another text box. You must specify the x- and y-coordinates of the text box as the parameters.In this example, you want to display a message in the multiline text box when the Show Message button is clicked. So you use the ButtonClickedevent and create a subroutine for displaying a message in the multiline text box.Check the output of your program by clicking the Run button on the toolbar or pressing F5 on the keyboard.Code:GraphicsWindow.DrawText(50, 100, &quot;Enter your first name:&quot;)firstname = Controls.AddTextBox(200, 100)GraphicsWindow.DrawText(50, 150, &quot;Enter your last name:&quot;)lastname = Controls.AddTextBox(200, 150)showbutton = Controls.AddButton(&quot;Show Message&quot;, 150, 200)message = Controls.AddMultiLineTextBox(50, 250)Controls.SetSize(message, 310, 50) Controls.ButtonClicked = ShowMessage SubShowMessageIfControls.GetButtonCaption(showbutton) = &quot;Show Message&quot; ThenControls.SetTextBoxText(message,&quot;Hello &quot; + Controls.GetTextBoxText(firstname) + &quot; &quot; + Controls.GetTextBoxText(lastname))EndIfEndSub
  • Code:Controls.SetSize(textbox, 300, 50)Controls.Move(textbox, 100, 150)Controls.LastClickedButtonControls.LastTypedTextBox
  • Notes:You can create simple programs in Small Basic by using controls such as text boxes and buttons. For example, take a look at the program displayed. In this program, we write a code to display two text boxes and a Search button. In the first text box, the user enters a word. On clicking the Search button, the definition of the word is displayed in the second text box. We use the Dictionary object to display the meaning of the word in the multiline text box.Code:GraphicsWindow.Title = &quot;Dictionary&quot;GraphicsWindow.Height = 600GraphicsWindow.Width = 600GraphicsWindow.DrawText(50, 80, &quot;Enter Text: &quot;)textbox = Controls.AddTextBox(50, 100)Controls.SetSize(textbox, 100, 30)Controls.SetTextBoxText(textbox, &quot;&quot;)GraphicsWindow.DrawText(50, 140, &quot;Dictionary Meanings: &quot;)multitxt = Controls.AddMultiLineTextBox(50, 160)Controls.SetSize(multitxt, 500, 400)Getdfn = Controls.AddButton(&quot;Search&quot;, 200, 100)GraphicsWindow.DrawText(80, 80, &quot;&quot;)meaning = Dictionary.GetDefinition(Controls.GetTextBoxText(textbox))Controls.SetTextBoxText(multitxt, meaning)Controls.ButtonClicked = ShowmeaningSub ShowmeaningIf Controls.GetButtonCaption(Getdfn) = &quot;Search&quot; Then meaning = Dictionary.GetDefinition(Controls.GetTextBoxText(textbox)) Controls.SetTextBoxText(multitxt, meaning)EndIfEndSub
  • Solution:GraphicsWindow.Show()GraphicsWindow.Width = 300GraphicsWindow.Height = 250GraphicsWindow.Top = (Desktop.Height - 450) / 2GraphicsWindow.left = (Desktop.Width - 600) / 2 GraphicsWindow.Title = &quot;Application Form:&quot;x = 30y = 37&apos;Enter NameGraphicsWindow.DrawText(x, y, &quot;Name:&quot;)NameTxtBox = Controls.AddTextBox(120, 35)Controls.SetSize(NameTxtBox, 150, 20) &apos;AddressGraphicsWindow.DrawText(x, y + 40, &quot;Address:&quot;)AddressTxtBox = Controls.AddMultiLineTextBox(120, 70)Controls.SetSize(AddressTxtBox, 150, 40)  &apos;Telephone detailsGraphicsWindow.DrawText(x, y + 90, &quot;Telephone:&quot;)TelphoneTxtBox = Controls.AddTextBox(120, 125)Controls.SetSize(TelphoneTxtBox, 150, 20) &apos;Email -idGraphicsWindow.DrawText(x, y + 125, &quot;E-mail ID:&quot;)EmailTxtBox = Controls.AddTextBox(120, 160)Controls.SetSize(EmailTxtBox, 150, 20) &apos;SubmitSubmitButton = Controls.AddButton(&quot;Submit&quot;, x + 30, y + 160)Controls.SetSize(SubmitButton, 70, 30) &apos;CancelCancelButton = Controls.AddButton(&quot;Cancel&quot;, x + 130, y + 160)Controls.SetSize(CancelButton, 70, 30) Controls.ButtonClicked = SubmitForm SubSubmitForm Name = controls.GetTextBoxText(NameTxtBox) Address = controls.GetTextBoxText(AddressTxtBox)Telphone = controls.GetTextBoxText(TelphoneTxtBox) Email = controls.GetTextBoxText(EmailTxtBox)IfControls.GetButtonCaption(Controls.LastClickedButton) = &quot;Submit&quot; ThenIf Name = &quot;&quot; or Address = &quot;&quot; or Telphone = &quot;&quot; or Email = &quot;&quot; ThenGraphicsWindow.ShowMessage(&quot;Please fill in all the details.&quot;, &quot;Error Message&quot;)ElseGraphicsWindow.ShowMessage(&quot;Your details have been submitted successfully!&quot;, &quot;Congratulations!&quot;)EndIfElseIfControls.GetButtonCaption(Controls.LastClickedButton) = &quot;Cancel&quot; ThenProgram.End() EndIfEndSub
  • 3.5 the controls object

    1. 1. Microsoft® Small Basic<br />The Controls Object<br />Estimated time to complete this lesson: 1 hour<br />
    2. 2. The Controls Object<br />In this lesson, you will learn about:<br />Using various properties of the Controls object.<br />Using control events on buttons and text boxes in your program.<br />Using various operations of the Controls object.<br />
    3. 3. Introduction to the Controls Object<br />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.<br />So far, you have learned to use different objects in Small Basic, such as the GraphicsWindow, Shapes, File, and Math objects.<br />
    4. 4. Operations of the Controls Object<br />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.<br />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.<br />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.<br />
    5. 5. Operations of the Controls Object<br />GetButtonCaption—With this operation, you can retrieve the caption of a button. You must specify the appropriate button name as a parameter. <br />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.<br />GetTextBoxText—You can retrieve the text present in a specified text box by specifying the text box name as a parameter for this operation.<br />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.<br />
    6. 6. Operations of the Controls Object<br />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.<br />Let’s explore the Controls object with the help of an example.<br />
    7. 7. Properties and Operations of the Controls object<br />Let’s look at the capabilities offered by a few more operations and properties of the Controls object. <br />HideControl—You can use this operation to hide an existing control from the graphics window.<br />ShowControl—This operation allows you to display a previously hidden control on the graphics window.<br />Remove—You can use this operation to remove a control from the graphics window. <br />
    8. 8. Properties and Operations of the Controls object<br />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.<br />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.  <br />LastClickedButton—You can use this operation to find the last button that was clicked on the graphics window.<br />LastTypedTextBox—You can use this operation to find the last text box where text was typed.<br />
    9. 9. The Controls Object<br />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.<br />output<br />
    10. 10. Control Events<br />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.<br />ButtonClicked raises an event when a button control is clicked.<br />TextTyped raises an event when text is typed into a textbox control.<br />And here’s an example of the TextTyped event:<br />You can use the ButtonClicked event to make a simple calculator as shown to the right:<br />
    11. 11. Let’s Summarize…<br />Congratulations! Now you know how to:<br />Usevarious properties of the Controls object.<br />Use various operations of the Controls object.<br />Use control events on buttons and text boxes in your program.<br />
    12. 12. It’s Time to Apply Your Learning…<br />Write a program to display a simple form, and perform the following steps:<br /><ul><li>Add text boxes to accept the name, address, telephone number, and e-mail address of the user.
    13. 13. Add a Submit button to the form.
    14. 14. When information is entered in all the text boxes and the Submit button is clicked, display an appropriate message. </li>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×