![]() Returns true if the Alt key is pressed otherwise, returns false. Table 3.5 Important Members of the KeyEventArgs Class Event handlers of these eventsreceive an argument of KeyEventArgs type it provides the propertieslisted in Table 3.5. The KeyDown and KeyUp events occur when the user pressesand releases a key on the keyboard, respectively. To handle keypresses for function keys,control keys, and cursor movement keys, you must use the KeyDown and KeyUp events. The KeyPress event fires only if the key that ispressed generates a character value. Returns the character value that corresponds to the key Indicates whether the event has been handled Table 3.4 Important Members of the KeyPressEventArgs Class Table 3.4 lists the properties of KeyPressEventArgs. Its event handler receives an argument of type KeyPressEventArgs. The KeyPress event happens after the KeyDown event butbefore the KeyUp event. You choose the event to program based on the orderin which the event is fired and the information that is passed in the eventargument of the event handler. You can program the event handlers for these events in order to performkeystroke-level validation. When you press a key on a control, three events take place, in the followingorder: The first technique is discussed relative to the use of various controls inChapter 2, "Controls" the following sections cover rest of thesetechniques. You can analyze the contents of the data field as a whole and warn theuser of any incorrect values when he or she attempts to leave the field or closethe window. You can restrict entry in some data fields by enabling or disabling them,depending on the state of other fields. You can capture the user's keystrokes and analyze them for validity.Some fields may require the user to enter only alphabetic values but no numericvalues or special characters in that case, you can accept the keystrokes foralphabetic characters while rejecting others. Theseallow users to select from a set of given values rather than permit freekeyboard entry. You can restrict the values that a field can accept by using standardcontrols such as combo boxes, list boxes, radio buttons, and check boxes. ![]() You can use various techniques for validatingdata: The most relevant place to ensure the validity of data is at thetime of data entry itself. When designing an application that acceptsdata from the user, you must ensure that the entered data is acceptable for theapplication. MCAD/MCSD Training Guide (70-316): Developing and Implementing Windows-Based Applications with Visual C# and Visual Studio.NET ![]()
0 Comments
Leave a Reply. |