Programming with Microsoft Visual Basic 2015 (MindTap Course List)
Programming with Microsoft Visual Basic 2015 (MindTap Course List)
7th Edition
ISBN: 9781285860268
Author: Diane Zak
Publisher: Cengage Learning
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 Visual Basic 2015 (MindTap Course List), 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 Visual Basic 2015 (MindTap Course List), 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
Capsim Team PowerPoint Presentations - Slide Title: Key LearningsWhat were the key learnings that you discovered as a team through your Capsim simulation?
Write the SQL code that permits to implement the tables: Student and Transcript. NB: Add the constraints on the attributes – keys and other.
Draw an ERD that will involve the entity types: Professor, Student, Department and Course. Be sure to add relationship types, key attributes, attributes and multiplicity on the ERD.
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
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L