CS 1400 Lab 5: Creating and Using TextBoxes
The objective of this lab is to write a Graphical User Interface program that uses Text Boxes to get input from the user and to display output to the user. It is important to note that the Text Property of a TextBox is a Reference-Type of String.
The best way to start this lab is to make a copy of the complete project folder that you created for Lab #4. Name this new project folder Lab05. Do not change any of the file names inside of your new folder.
Changing the Interface
Figure 1: Lab 5 Form and Controls
Creating An Event Handler
The objective of this program is double the value that the user enters into the top TextBox, and display the result in the bottom TextBox. When the user enters a value into the TextBox and presses the tab key, you program should double this value and display the result in the bottom TextBox. When the cursor leaves a TextBox, we say that the TextBox loses Focus. To have your TextBox generate an event when it loses focus, follow these instructions (see Figure 2):
Figure 2: Picking the Leave Event
The code that you enter into your event handler will:
All of this is required because the data that is shown in a TextBox is always a string and when we do arithmetic, we need to use a number. For this example I have named my TextBoxes inTxtBox and outTxtBox.
// The inTxtBox_Leave Method
When you submit your lab to Canvas, answer these two questions by adding a comment to your submission.
Question #1: Given a variable, cash that contains a currency amount like $4.56, what would the statements look like that would properly format and output that variable in a TextBox?
Question #2: Suppose that you wanted this program to halve the number input by the user. Write the line of code that would do that.
Now build and test your code. Make sure that your code is properly documented and meets all of the style guidlines. When it runs to your satisfaction submit your lab to Canvas.
Submitting Your Lab
Place your complete project folder into
a zip file and name the zip file