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 VIS PKG
- How can the user access a button whose Text property contains Clea&r? a. Alt+r b. Ctrl+r c. Shift+r d. Esc+rarrow_forwardCOM. 1).When you select a radio button , its Checked property changes from True to False , invoking its CheckedChanged event . True False 2) You have been hired by PetPals Veterinary Clinic to modify its Bill Calculator application . Upon reviewing the application , you notice that all of the controls have their default names . You also notice that the Calculate buttonscode uses the properties of controls in the calculation statements . Two procedures in the PetPals Clinic application need access to the same variable . You can accomplish this by declaring the variable using the____________keyword in the form's declarations section . Const Share Private Valarrow_forwardWhen the contents of a text box change, the text box’s event occurs.a. ChangedTextb. ModifiedTextc. TextModifiedd. TextChangedarrow_forward
- This question requires that you evaluate the underlined text to determine if it is correct. You are writing an app for Best For You Organics Company. The app needs to allow the user to convert a recipe from cups to liters. The app will use the conversion ratio of 1 cup is equal to 0.2366 liters. You define the pseudocode as follows: INPUT cups liters = cups * 0.2366 OUTPUT liters Review the underlined text. If it makes the statement correct, select “No change is needed.” If the statement is incorrect, select the answer choice that makes the statement correct. Group of answer choices Cups / .02366 * 10 Cups / 0.2366 Cups * 2.366 No change is needed.arrow_forwardHow can you prevent the user from editing the contents of a text box during run time?a. set the text box’s Editable property to Falseb. set the text box’s Changeable property to Falsec. set the text box’s ReadOnly property to Trued. set the text box’s WriteOnly property to Falsearrow_forwardWhich property allows you to specify a specific character that will always be displayed in a text box, no matter what character the user types? a. Char b. CharPassword c. Password d. PasswordChararrow_forward
- To make the btnCalc control the default button, you need to set the _____________________ property. a. btnCalc’s AcceptButton b. btnCalc’s DefaultButton c. form’s AcceptButton d. form’s DefaultButtonarrow_forwardC++ programming, please follow the flowchart PLEASE. thank you for helping #include <iostream> #include <iomanip> double double showMenu(); double takePurchase(double); double takePayment(); double takePayment(); void displayInfo(double, double); double showMenu() {} double takePayment() { double takePurchase()arrow_forwardCreate a TaxApp windows application that calculates the tax percentage. Include appropriate (PYTHON)labels, entry box for each input entry, and a button labeled Compute. Your app should satisfythe following requirements:1. Define the Click event for a Button to calculate and display the value of the Total Due(Total Amount * Tax Percentage). Check if all the controls carry values (for example ifnothing is entered, display a warning message)2. Note that Text property is of string type and require conversion before arithmetic isperformed.3. The font color for all objects should be of your choice. Change the background color ofthe objects also to an appropriate one to use with your font color. To change thebackground color of the form you can use configure method (For example,window.configure (bg='blue'))arrow_forward
- Create a lottery game application. Generate three random numbers, each between 0 and 9. • Allow the user to guess three numbers.• Compare each of the user’s guesses to the three random numbers and display a message that includes the user’s guess, the randomly determined three-digit numberarrow_forwardQuestion p Create a tkinter application to accept radius of a circle and display the area using .Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardIf the txtGrossPay control contains the number 1234.78, what number will theInteger.TryParse(txtGrossPay.Text, intGross) statement assign to theintGross variable?arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning