How to Control the Occurrence of a Default EventLast reviewed: April 30, 1996Article ID: Q131095 |
The information in this article applies to:
SUMMARYAn event is an action generated by a user, a program, or the system. When an event is triggered, Visual FoxPro processes some default system tasks. For example, pressing a key triggers the keypress event that causes the letter to be displayed in a text box. With Visual FoxPro, you can control the occurrence of system events. This article describes how to prevent system processing of events, and how to cause default events to occur before user-generated or code-generated events occur. You can add code to a method to customize operations that occur when an event is triggered. When an event handler is customized, system processing occurs in addition to the tasks defined in user code. By default, the user code is processed first followed by system processing.
MORE INFORMATION
Preventing System Processing from OccurringUse the NODEFAULT keyword in method code to prevent system processing of events. For example, in an input field, you can prevent some characters from being displayed by using the NODEFAULT clause in a Keypress event handler. The default behavior when a key is pressed is to display the character being typed. The NODEFAULT keyword is used in the MAIN form of the CONTROLS project located in the SAMPLES\CONTROLS directory. For more information about NODEFAULT, search for DEFINE CLASS in the Visual FoxPro Help menu.
Forcing System Processing to Occur Before User-Defined Code Is ProcessedYou can cause the system code for the event to be processed first - before the user-defined code is prcessed. This is useful, for example, if you want to control the starting position of a text selection when the control gets the focus. Default processing of the GotFocus event causes the SelStart property to be set to zero (0), and the insertion point (cursor) is positioned before the first character displayed in the control. You can't just set the value of the SelStart property in the GotFocus event because the GotFocus default processing occurs after user code is processed, so the SelStart property is reset to zero (0). The default processing of the GotFocus event must occur before the value of the SelStart property is customized. To make the default processing occur first, you need to modify the GotFocus event code in the GotFocus event handler to follow this sequence:
Sample Code to Place in the GotFocus Method of a Text Box Control* First, force default processing: Textbox::GotFocus() * Set the SelStart property: This.SelStart = 4 * Default processing already occurred, so prevent it from occurring again: NODEFAULT
|
Additional reference words: 3.00 VFoxWin form selection
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |