The text box’s “KeyPress” event occurs when pressing any key in the keyboard.
Hence, correct answer is option “D”.
Explanation of Solution
The KeyPress event:
If a key is pressed within a control (i.e. the control has been focused), then the KeyPress event will occur.
- The keyPress event procedure sends the pressed key’s character to the “e” parameter of the keyPress event.
- The acceptance of pressing key has been handled by using the property “Handled”.
e.Handled
- “Handled” property contains the Boolean values “True” or “False”.
- If the “Handled” property of the control is “true”, then the control cancels the pressed keys.
e.Handled = True
- If the “Handled” property of the control is “false”, then the control accepts the pressed keys.
e.Handled = False
Example:
The sub procedure “CancelKeys” allows the text boxes “txtCode” and “txtSales” to accept only the numbers and the backspace key.
Private Sub CancelKeys(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles txtCode.KeyPress, txtSales.KeyPress
'Allows only numbers and the Backspace key in the 'text box
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
'Cancel the key
e.Handled = True
End If
End Sub
The above example is used to accept only the numeric value keys and the backspace key.
Output:
Note: Here, it does not accept the keys other than the numeric and backspace key.
Enter “12” as code. Then, press backspace key to delete the 2.
Screenshot of “Bonus Calculator” form
The 2 will be deleted after pressing the backspace key.
Screenshot of “Bonus Calculator” form
Want to see more full solutions like this?
Chapter 4 Solutions
Programming with Microsoft Visual Basic 2015 (MindTap Course List)
- Tip, Tax, and Total Create an application that lets the user enter the food charge for a meal at a restaurant. When a button is clicked, the application should calculate and display the amount of a 15 percent tip, 7 percent sales tax, and the total of all three amounts.arrow_forwardWhen entering data in a text box, each key the user presses invokes the text box’s _____________________ event. a. Focus b. Key c. KeyFocus d. KeyPressarrow_forwardChoose correct option The code contained in the ............... allows an application to retrieve the contents of the Private variable associated with the property. Getter Block Retrieve Set Block Get Blockarrow_forward
- If you know a vehicle’s speed and the amount of time it has traveled, you can calculate the distance it has traveled as follows:Distance = Speed × TimeFor example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Create an application with a form. The user enters a vehicle’s speed and the number of hours traveled into text boxes. When the user clicks the Calculate button, the application should use a loop to display in a list box the distance the vehicle has traveled for each hour of that time period.arrow_forwardYou can modify the tab order by changing a control’s____________________property.arrow_forwardTheater RevenueA movie theater only keeps a percentage of the revenue earned from ticket sales. The remainder goes to the movie company. Create a GUI application that allows the user to enter the following data into text fields:� Price per adult ticket� Number of adult tickets sold� Price per child ticket� Number of child tickets soldThe application should calculate and display the following data for one night�s box office business at a theater:� Gross revenue for adult tickets sold. This is the amount of money taken in for all adult tickets sold.� Net revenue for adult tickets sold. This is the amount of money from adult ticket sales left over after the payment to the movie company has been deducted.� Gross revenue for child tickets sold. This is the amount of money taken in for all child tickets sold.� Net revenue for child tickets sold. This is the amount of money from child ticket sales left over after the payment to the movie company has been deducted.� Total gross revenue. This…arrow_forward
- Many financial experts advise that property owners should insure their homes or buildings for at least 80 percent of the amount it would cost to replace the structure. Create an application that lets the user enter the replacement cost of a building and then displays the minimum amount of insurance he or she should buy for the property.arrow_forwardCheck the correct in checkbox The preprocessor removes the _______ from the source code. comments header files both comments and header files none of the mentionedarrow_forwardName Formatter Create an application that lets the user enter the following pieces of data: • The user’s first name • The user’s middle name • The user’s last name • The user’s preferred title (Mr., Mrs., Ms., Dr., etc.) Assume the user has entered the following data: • First name: Kelly • Middle name: Jane • Last name: Smith • Title: Ms. The application should have buttons that display the user’s name formatted in the following ways: Ms. Kelly Jane Smith Kelly Jane Smith Kelly Smith Smith, Kelly Jane, Ms. Smith, Kelly Jane Smith, Kellyarrow_forward
- Falling Distance When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period: d =1/2gt2 The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time in seconds that the object has been falling. Create an application that allows the user to enter the amount of time that an object has fallen and then displays the distance that the object fell. The application should have a method named FallingDistance. The FallingDistance method should accept an object’s falling time (in seconds) as an argument. The method should return the distance in meters that the object has fallen during that time interval.arrow_forwardCSCI 294, C# Programming Homework 07 – Trivia Game Assignment For this assignment you are to create a trivia game using Visual C#. Select any topic you wish and make a game that asks four trivia questions on that topic. All four questions should appear at the same time on the applications form. Each question should have at least four possible answers for the user to choose from. Two of the questions must use radio buttons for the answers and two must use check boxes. Provide a button that evaluates and displays the user's score. This assignment is intentionally open-ended. I want to allow you to be creative and perhaps have some fun writing a C# application. What to Turn In Submit a Compressed zip file of the entire Virtual Studio project folder created for you application.arrow_forwardPlease answer the question below 13. Choose correct option A button’s _______ event is used to run code. OnClick onclick Click clickarrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning