PROGRAMMING WITH MICROSOFT VIS PKG
PROGRAMMING WITH MICROSOFT VIS PKG
7th Edition
ISBN: 9781337088152
Author: ZAK
Publisher: CENGAGE L
Expert Solution & Answer
Book Icon
Chapter 4.LC, Problem 1RQ
Program Description Answer

The text box’s “KeyPress” event occurs when pressing any key in the keyboard.

Hence, correct answer is option “D”.

Expert Solution & Answer
Check Mark

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.

Sample Output

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

PROGRAMMING WITH MICROSOFT VIS PKG, Chapter 4.LC, Problem 1RQ , additional homework tip  1

The 2 will be deleted after pressing the backspace key.

Screenshot of “Bonus Calculator” form

PROGRAMMING WITH MICROSOFT VIS PKG, Chapter 4.LC, Problem 1RQ , additional homework tip  2

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Please answer the question below   13. Choose correct option A button’s _______ event is used to run code.  OnClick  onclick  Click  click
If a text box’s access key is the letter y, you can move the focus to the text box by pressing__________ .a. Alt+yb. Ctrl+yc. Esc+yd. Shift+y
When entering data in a text box, each key the user presses invokes the text box’s _____________________ event. a. Focus b. Key c. KeyFocus d. KeyPress
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning