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
Loading
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.
<<PreviousNext>>

The Masked Text Box

Back to the phone number example, keying in the name should be a simple process; however, the phone number field has a defined pattern. The area code, which is enclosed in a pair of parentheses, is followed by a three-digit prefix, a hyphen, and a four-digit number. The parentheses and hyphens are in fixed positions. If you have a control that can show these fixed characters automatically, you will not only force the user to follow the pattern, but also save the user four keystrokes, a nearly 30% improvement in keying efficiency. The masked text box is a VB control that can handle this defined pattern. This control has a Mask property, which, when left blank, will cause the control to act like a standard text box, but the property can be set to expect and conveniently enforce a desired input pattern.
To include this control in your project, follow these steps:

The Mask Property

The masked text box has a Mask property, which can be set to a predefined phone number mask (999)000-0000. To set the mask,

  1. Click the Mask property in the control’s property window.
  2. Click the ellipsis (…) button in the Mask property box to invoke the Input Mask dialog box.
  3. Select Phone number in the dialog box and click the OK button.
  4. You should see the mask appear in the control’s mask property box (Figure 3.4).

Start the program and try it.
The 9 in the mask accepts an optional digit or space, while the 0 is a placeholder for a required digit, and the parentheses and hyphen are literals. At runtime, the literals present themselves in their respective positions, but the 9’s and 0’s disappear. Many more mask characters are available for different uses. For example, an L mask character is a placeholder for a required alphabetic letter. Explore the Help file for many additional mask features of this control, as suggested in the Look It Up box that follows.

Figure 3-4
Masked text box and its Mask property

Look it up
Search the online help screen using mask property as the keyword in the Index tab. The page for MaskedtextBox.Mask Property provides a complete list of mask characters used in the mask property of the masked text box. You will most likely need to visit this page from time to time when you have a special requirement for the masked text box.
Last change: February 13 2016 18:47:27.
<<PreviousNext>>