Ask the MultiValued Visual Basic Expert - #5

(as published in Spectrum magazine)

updated November 17, 1997

To email your questions to "Ask the MultiValued VB Expert", click here.
Copyright © 1996-97 Caduceus Consulting. All rights reserved.

Visual Basic Event Sequences

Many user actions invoke multiple Visual Basic events, but which events? and in what order? None of the VB manuals appear to document this, but I recall that you had researched this. Would you share your results? - L. Burstein, Dynamic Systems

No problem. I too got frustrated by being unable to find this information anywhere. The table below gives some of the multiple and/or unusual event sequences that I found:

Action Events triggered (in order)
form load Form_Load
Form_Resize
Form_Activate
firsttabindexcontrol_GotFocus
Form_Paint
form minimize Form_Resize
form restore from icon Form_Paint (note: no Form_Resize)
form maximize Form_Resize
Form_MouseMove (note: even with no mouse movement!)
Form_Paint
form restore from max Form_Resize
form move by drag Form_MouseMove...
form resize by drag Form_MouseMove...
Form_Resize
Form_Paint
Form_MouseMove... (note 2nd 'relative' move)
form close Form_QueryUnload
Form_Unload
click in text box Text1_MouseMove... (only when Text1.Enabled is True)
(sets Text1.SelStart BEFORE MouseDown event)
Text1_MouseDown (note: before LostFocus!)
prevcontrol_LostFocus
Text1_GotFocus
Text1_MouseUp
Text1_Click
single character in text box Text1_MouseMove...
Form_KeyDown (if Form.KeyPreview is True)
Text1_KeyDown
Form_KeyPress (if Form.KeyPreview is True)
Text1_KeyPress
Text1_Change
Form_KeyUp (if Form.KeyPreview is True)
Text1_KeyUp
combo box set by listindex Combo1_Click (note: no Change event!)
single character in combo box Combo1_GotFocus
Combo1_KeyDown
Combo1_KeyPress
Combo1_Change
Combo1_KeyUp
combo box select Combo1_DropDown (note: before GotFocus!)
Combo1_GotFocus
Combo1_Click (note: no Change event!)
click on grid cell Grid1_RowColChange (note: before GotFocus!)
Grid1_MouseDown
Grid1_GotFocus
Grid1_SelChange
Grid1_MouseUp
Grid1_Click
click on Command1 while in Text1 Form_MouseMove...
Command1_MouseDown (note: before LostFocus!)
Text1_LostFocus
Command1_GotFocus
Command1_Click (note: before MouseUp!)
Command1_MouseUp
tab from Text1 to Text2 Text1_LostFocus (note: LostFocus before GotFocus)
Text2_GotFocus

Important things to note from all this:

bulletWhen you click on a control other than the current one, the MouseDown event happens BEFORE the previous control's LostFocus event, and BEFORE the new control's GotFocus event. One valuable use of this is that you can detect the user clicking the Cancel button and programatically avoid running data validation in the LostFocus event of whatever field they were in before clicking Cancel.
bulletThe Click event for a Command button happens BEFORE the MouseUp event, while for most other controls, it happens AFTER the MouseUp event.
bulletA number of controls have events that happen BEFORE the GotFocus event. For example, you can build or adjust the list of a ComboBox in the DropDown event before GotFocus. In the Grid control, you get a RowColChange event before the GotFocus event.
bulletWhen you click in a TextBox, the SelStart property is set (based on the position of the mouse) before ANY other event takes place.

To email your questions to "Ask the MultiValued VB Expert", click here.
Copyright © 1996-97 Caduceus Consulting. All rights reserved.
Revised: November 17, 1997.

Return to Caduceus Consulting Home Page

Copyright © 2006 intellact
Last modified: Thursday May 25, 2006