Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 3: User Interface Design: Visual Basic Controls and Events
Last change: February 13 2016 18:47:26.

Before the User Does Anything in a Control: The Enter Event

Sometimes when the user tabs into a field or clicks the field to set the focus, you want your program to perform some preparatory activities, such as keeping the current content of the control in a variable (as a backup) or highlighting the content to facilitate editing. When the user tabs into a control, the control’s Enter event is triggered. The code placed in this event will be executed as soon as the control gets the focus. For example, suppose you want to keep the current content of a text box named txtName before the user starts doing anything on the field so that when the user presses the Esc key, you can restore the content. You can code the following:

Private Sub txtName_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.Enter PreviousName = txtName.Text End Sub

Note that the preceding code keeps only the content of the text box in a variable named PreviousName. To restore the content when the user presses the Esc key, more code will be needed. You should be able to complete this exercise by the time you finish Chapter 4.

Last change: February 13 2016 18:47:25.