Form events
A RDFormsFormWindow raises its root's own events to the window's sink, in the order VB6 raises them (measured with VB6).
Initialize, Load and Terminate are the program's: the window raises none of them. A program raises Initialize and Load before it shows the window.
Showing and resizing
| Situation | Raised |
|---|---|
| The window is shown for the first time | Resize, inside Show, then Activate. |
The root's Width or Height changes |
One Resize for each change, inside the assignment. A size the root already has raises nothing. |
| The user resizes the window | The root's Width and Height take the client area's size, in whole pixels, and one Resize is raised for both. |
The window is shown again after Hide |
No Resize. |
Once its window has been shown, the root raises Resize for a change of size whether the window is hidden or not. With AutoRedraw False, Paint follows Resize as the window is shown and as its client area grows: see Drawing.
Activation
| Situation | Raised |
|---|---|
| The window is shown for the first time | Activate, then GotFocus on the first control of the tab order that can take the focus. |
| Another of the program's form windows becomes active | On the form that was active, LostFocus on its focused control, then Deactivate; then, on the new one, Activate, then GotFocus on its control. |
| Another application, or another program's form window in the same process, takes the activation and gives it back | Nothing. Each program has its own active form. |
| A window whose root is disabled is shown | No Activate: it is shown without being activated. |
Each form keeps the control that last had the focus on it: that control takes the focus again, with a GotFocus, when the form is activated again. A form with no control that can take the focus raises its own GotFocus after its Activate, and its own LostFocus before its Deactivate. That LostFocus was not measured with VB6: its place before the Deactivate is RDForms' own.
Leaving a control
As the focus moves from a control of the active form to another of its controls, by the keyboard or the mouse, the control it leaves raises these events in order:
- BeforeUpdate, then AfterUpdate, where the control is a TextBox whose text the user changed since the focus last left it. A change from code raises neither.
- Validate, where the control that takes the focus has
CausesValidationTrue, the default. - LostFocus, then the other control's GotFocus.
A handler that sets Cancel to True, in BeforeUpdate or in Validate, keeps the focus on the control: nothing else is raised, and the edit stays. The next move raises the events again. A move made by SetFocus raises no Validate.
The order of BeforeUpdate, AfterUpdate and Validate is RDForms' own: an MSForms UserForm raises BeforeUpdate and AfterUpdate before its Exit, which ports to Validate.
Note
Not implemented. The other controls with a value (ComboBox, ListBox, CheckBox, OptionButton, the scroll bars, MultiPage and TabStrip) declare BeforeUpdate and AfterUpdate and raise neither. BeforeDragOver, BeforeDropOrPaste and Error are declared on the controls and containers MSForms gives them, with RDForms.DataObject and RDForms.ReturnEffect arguments, and never raised. A MultiPage's and a TabStrip's take the page's or the tab's Index first, and a MultiPage's Error does too.
Unloading
| Situation | Raised |
|---|---|
| The user clicks the close box | QueryUnload with an UnloadMode of 0, then Unload. |
Unload is called, as VB's Unload statement |
QueryUnload with an UnloadMode of 1, then Unload. It returns whether the form unloaded. |
Close is called, as VB's End closes a form |
Nothing. |
Unload is called from the root's own QueryUnload or Unload |
Nothing: it returns False and the unload goes on. |
A handler that sets Cancel to a value other than 0, in QueryUnload or in Unload, keeps the window open. A window closed for its owner closing raises them with an UnloadMode of 5, and one closed as Windows ends its session with 2.
A host whose program raises QueryUnload and Unload itself sets the window's UnloadRequestHandler. The user's close then raises nothing and leaves the window open: the handler gets the UnloadMode, and the host closes the window with Close once the program has unloaded the form.
Mouse
A press on none of the form's controls is the root's.
- It raises MouseDown, MouseMove and MouseUp.
XandYare in the root's scale: itsScaleMode, from itsScaleLeftandScaleTop. - Click comes after MouseUp, for the right and middle buttons too, where the release is over the form again, wherever the press was.
- A release over a control, or outside the window, raises the root's MouseUp and no Click.
- A double click's second press raises DblClick in place of its MouseDown, and its release raises MouseUp and no Click.
Keyboard
| Focus | Raised on the root |
|---|---|
| On none of the form's controls | KeyDown, KeyPress and KeyUp, for every key. |
On a control, with the root's KeyPreview False |
Nothing. |
On a control, with the root's KeyPreview True |
Each key event, before the control's. |
With KeyPreview True, the root's handlers decide what the control raises:
- A
KeyCodethe root's KeyDown sets to 0 raises no KeyDown on the control, and the key still does what it does, except on a scroll bar, which it does not move. Another code is not passed on: the control's KeyDown has the key's own code. - The control's KeyPress has the
KeyAsciithe root's KeyPress left, and 0 raises none and types nothing. - The control's KeyUp has the key's own code.
The root's KeyPress follows the TextBox's rules: a character outside ASCII raises none, Backspace is 8 and Ctrl+A is 1.
A control's key events
The TextBox, CommandButton, CheckBox, OptionButton, ListBox, ComboBox, HScrollBar and VScrollBar raise their own KeyDown, KeyPress and KeyUp, in the order measured with VB6: KeyDown, KeyPress for a key that types a character, then what the key does, then KeyUp. With KeyPreview True, each of the root's events comes just before the control's.
| Key | Raised |
|---|---|
| Space on a CommandButton or a CheckBox | KeyDown, KeyPress 32 and KeyUp, then Click. |
| Space on the selected OptionButton | KeyDown, KeyPress 32 and KeyUp, and no Click. |
| An arrow on a CommandButton, a CheckBox or an OptionButton | No key event, not even the root's: the focus moves. The control that takes the focus raises its KeyUp alone, except a CommandButton, a CheckBox or an OptionButton, which raises none. |
| An arrow in a ListBox or a ComboBox | KeyDown, the Click of the selection, then KeyUp. |
| A character in a ListBox or a ComboBox | KeyDown, KeyPress, the Click of the selection or the Change of the text, then KeyUp. |
| An arrow, Page Up, Page Down, Home or End on a scroll bar | KeyDown, the Change where the value moves, then KeyUp. A KeyCode of 0 left by its KeyDown moves nothing. |
| Enter or Esc that no button takes | KeyDown, KeyPress 13 or 27, then KeyUp. Enter on a CheckBox or an OptionButton changes no Value. |
| Ctrl+Enter | KeyDown, KeyPress 10, then KeyUp. No button takes it. |
A control's KeyPress follows the TextBox's rules: a KeyAscii of 0 types nothing, and another code is taken in place of the character.
A PictureBox raises its own key events too, by rules that are RDForms' own: see PictureBox.
Enter and Esc
A CommandButton whose Default is True is the form's default button, and one whose Cancel is True its cancel button. Enter clicks the default button and Esc the cancel button from any control of the form, except that a focused CommandButton takes Enter itself and a ComboBox's open list keeps both keys.
| Key | Raised |
|---|---|
| Enter, with a default button | The default button's Click, and no key event anywhere, the root's included under KeyPreview. A handler cannot keep the key from the button. |
| Esc, with a cancel button | The cancel button's Click, and no key event anywhere. |
| Enter on a focused CommandButton | Its own Click, and no key event, whether or not the form has a default button. |
| Enter or Esc in a ComboBox's open list | KeyDown and KeyPress on the combo, and the list closes. No button is clicked. The KeyUp is raised only where the form has no default button, for Enter, or no cancel button, for Esc. |
| Enter or Esc on a form with no controls | The root's KeyDown, KeyPress 13 or 27, and KeyUp. |
Where more than one CommandButton has Default or Cancel True, the first the form holds takes the key. A default or cancel button that is hidden or disabled takes no key: Enter and Esc go to the focused control as other keys do. Neither case was measured with VB6: these two rules are RDForms' own.
What a character typed in a ListBox selects is on the Lists page.
Converting from MSForms
The handlers of an MSForms form and its controls take these names and parameters in RDForms (see Converting from MSForms):
| MSForms | RDForms |
|---|---|
UserForm_Initialize, UserForm_Activate and the form's other handlers |
Form_Initialize, Form_Activate, and so on. |
UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) |
Form_QueryUnload, its parameters as declared. |
Enter() |
GotFocus(). |
Exit(ByVal Cancel As MSForms.ReturnBoolean) |
Validate(Cancel As Boolean). Validate is raised only where the control that takes the focus has CausesValidation True: RDC40008 marks each Exit handler ported. |
BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean), AfterUpdate() |
BeforeUpdate(Cancel As Boolean), AfterUpdate(). |
DblClick(ByVal Cancel As MSForms.ReturnBoolean) |
DblClick(Cancel As Boolean). |
KeyPress(ByVal KeyAscii As MSForms.ReturnInteger), and KeyDown's and KeyUp's KeyCode |
KeyAscii As Integer, KeyCode As Integer. |
MouseDown, MouseMove and MouseUp, X and Y in points |
The same, X and Y in twips (20 to a point), and a form's own in its scale. |
| BeforeDragOver, BeforeDropOrPaste and Error | The same, with RDForms.DataObject, RDForms.ReturnEffect, RDForms.fmDragState and RDForms.fmAction, and ByRef values for the Return* wrappers. |
ACCUEIL • HOME | BIENVENUE • WELCOME | DÉMARRER • GET STARTED | IMPORTER • IMPORT | CONTROLS | FORMAT | 🌐 rubberduckvba.ca