Windows form events sequence
If you have changed data in a control, the BeforeUpdate and AfterUpdate events for both the control and the form occur before the Exit event for the control. When you open a form that contains a subform, the subform and its records are loaded before the main form. Thus, the events for the subform and its controls such as Open , Current , Enter , and GotFocus occur before the events for the form.
However, the Activate event does not occur for subforms. Therefore, opening a main form triggers an Activate event only for the main form. Similarly, when you close a form that contains a subform, the subform and its records are unloaded after the form. The Deactivate event does not occur for subforms.
Therefore, closing a main form triggers a Deactivate event only for the main form. The events for the controls, form, and subform occur in the following order:. Events for the subform's controls such as Exit and LostFocus. Events for the form such as Deactivate and Close. Note: Because the events for a subform occur after the main form is closed, certain events, such as canceling the closing of the main form from an event in the subform, will not occur.
You may need to move these types of validation tests to an event on the main form. Keyboard events occur for forms and controls when you press keys or send keystrokes while the form or control has the focus.
Mouse events occur for forms, form sections, and controls on forms when you click the mouse buttons while the mouse pointer is on a form, section, or control. Mouse events also occur when you move the mouse pointer over a form, section, or control. When you press and release a key while a control on a form has the focus or use the SendKeys action or statement to send a keystroke , the following sequence of events occurs:.
If pressing a key triggers another event for a control, that event occurs after the KeyPress event but before the KeyUp event. For example, if a keystroke changes text in a text box, which triggers a Change event, the following sequence of events occurs:. If a keystroke causes the focus to move from one control to another control, the KeyDown event occurs for the first control, whereas the KeyPress and KeyUp events occur for the second control.
For example, if you change data in a control and then press the TAB key to move to the next control, the following sequences of events occur:. When you click and release a mouse button while the mouse pointer is on a control on a form, the following sequence of events occurs for the control:.
MouseDown MouseUp Click. If a control has the focus and you click another control to move the focus to this second control, the following sequences of events occur:. If you move to another record and then click a control, the Current event for the form also occurs before the Enter event for the control.
Double-clicking a control causes both the Click and DblClick events to occur. For example, when you double-click a control other than a command button, the following sequence of events occurs for the control:. When you double-click a command button, the preceding sequence of events occurs, followed by a second Click event.
The MouseMove event for a form, section, or control occurs when you move the mouse pointer over the form, section, or control. This event is independent of the other mouse events. Events occur for reports and report sections when you open a report to print or preview it, or close a report.
When you open a report to print or preview it and then later close the report or move to another object tab in Access, the following sequence of events occurs for the report:. Open Activate Close Deactivate.
When you switch between two open reports, the Deactivate event occurs for the first report, and the Activate event occurs for the second report:. Deactivate report1 Activate report2.
The Deactivate event for a report also occurs when you switch from the report to another object tab in Access. When you open a report that is based on a query, Access triggers the Open event for the report before it runs the underlying query.
As a result, you can set the criteria for the report by using a macro or event procedure that responds to the Open event. For example, the macro or event procedure can open a custom dialog box in which you enter report criteria. There are several variations to the general case, but let's start by assuming that the grid edit mode DataGridView. EditMode is EditOnKeystroke and that all cells, all rows, and the grid, are valid. That allows navigation of the grid without slipping into edit mode.
As we move from one cell to another, we see in this order :. The OnCellLeave event will always occur when an attempt is made to navigate away from a cell. Additional Leave events may occur, depending on where we move to. For example:. Leave events are straightforward, in the sense that future events are not affected by any change to arguments in the Leave event handler.
When the Leave events are complete, the Validation events will start to fire. You'll recognise the order from above. Everything validated, so the cell focus can move as intended, and the event sequence completes by firing the Enter events for the new cell.
Put all that together and when moving from a valid cell C1 in valid row R1 to cell C2 in row R2, the following sequence of events will fire:. Now as mentioned, that's just one case and there are many variations, so let's follow this case i. Begin at state 1 in the top left of the diagram. In this state, one of the cells is selected but not being edited. When a cell on another row is selected, the transition to state 5 occurs.
FormClosed Occurs after the form is closed. Deactivate Occurs when the form loses focus and is no longer the active form. Control Structures — The Loop. Categories ASP. This website uses cookies We are using cookies to help make this website better. More details can be found in our Privacy Policy. Got it - do not show this message again. Privacy Policy. Close Privacy Overview This website uses cookies to improve your experience while you navigate through the website.
Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent.
You also have the option to opt-out of these cookies.
0コメント