Its value is one of the values specified inthe Keys enumeration. True if the Ctrl key is pressed otherwise False. True if the Alt key is pressed otherwise False. Table 3.5 Important Properties of the KeyEventArgs Class These use the properties of the KeyEventArgs class, detailed in Table 3.5. Torespond to the excluded keys, you must use the KeyDown and KeyUp events instead. The KeyPress event only fires for keys that generatecharacter values, excluding function, control, and cursor-movement keys. The character value corresponding to the pressed key. Indicates whether the event has been handled. Table 3.4 Important Properties of the KeyPressEventArgs Class The KeyPress event may be used in order to intercept input keyboardcharacters and perform validation tasks through the use of the KeyPressEventArgs class before the KeyUp event is handled.Table 3.4 details some important properties of the KeyPressEventArgsclass. When a user presses a key, three events are fired in order: If the ReadOnly property of a TextBox control is set toTrue, it may still receive focus, allowing users to scroll through its contentswhile preventing changes. When a control's Enabled value is set to False, it cannotreceive focus. Manipulating access properties such as the Enabled and ReadOnly properties can be used to restrict data entry access within acontrol. This property does not restrict thelength of values that may be input programmatically. Avalue of zero (the default) specifies no specific limit to the number ofcharacters that may be input by the user. The MaxLength property of a TextBox or ComboBox control is used torestrict the maximum number of characters the user can input into the control. The options for the CharacterCasing property are Normal (the default, which does not changethe case of input characters), Upper (which forces all input to uppercase), andLower (which forces all input to lowercase). The CharacterCasing property of a TextBox control may be used toforce all input alphabetic characters to a particular case. Of note are the CharacterCasing and MaxLength properties used in text-input controls such as the TextBoxcontrol. You can restrict the allowable values within a control by using theproperties that we discussed in Chapter 2, "Controls on Forms." Inaddition to simply restricting input to a selection from a list of values,configuration of control properties may be used in order to further limitpossible input values. This is often used to warn a user whenattempting to change focus from the control or close the form. This might be used to prevent the entry of symbols oralphabetic characters within a control that should hold only numericcharacters.Įvaluating a control's data as a whole and warning the user ofincorrect or unacceptable values. As an example of this technique, a set ofcontrols allowing for the entry of address information might remain disableduntil a valid customer ID has been selected in another control.Ĭapturing and evaluating user keystrokes and allowing only acceptablevalues to be recognized. Restricting data entry through controls by enabling or disabling thembased on the state of other controls. Configuring the properties of the controls allows for additionalrestriction of user input, such as controlling the case or length of text boxinput. Controls such asRadioButtons, ListBoxes, ComboBoxes, and CheckBoxes are often used for this typeof validation. Restricting the available values by using the proper type of control,configured with a specific list of allowed values. Here are the four basic techniques used tovalidate user input: Validating user input before it is evaluated provides abetter solution than complex exception-handling code that may add a great dealof resource overhead to your program. In order to make your application as robust as possible, the best solution toinvalid or incorrect user input is to prevent the entry of "bad" dataas often as possible. MCAD Developing and Implementing Windows-based Applications with Microsoft Visual Basic.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |