PRB: VB Form_Load Procedure Not Executed when Unload Not UsedLast reviewed: June 21, 1995Article ID: Q76629 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0
SYMPTOMSCode inside a Form_Load event procedure will not execute under the circumstances described in this article. The example below helps clarify the behavior of the Load event procedure.
CAUSEA Load event procedure executes only when a form is loaded, either with the Load statement or an implicit load. An implicit load is caused when a form is currently not loaded, and a property or method accesses the form or associated control.
STATUSThis behavior is by design.
MORE INFORMATIONBelow is a demonstration of this behavior:
WorkaroundThe easiest way to work around this behavior is to add an Unload statement after each .Show statement, as shown below:
Sub Command1_Click () Form1.MousePointer = 11 Form2.Show Unload Form1 'new line of code to be added End Sub Sub Command2_Click () Form2.MousePointer = 0 Form1.Show Unload Form2 'new line of code to be added End SubNOTE: This method may slow the painting of forms at run-time, but this method will guarantee that the Form_Load event procedure is executed when the Show method is executed. Another workaround is to place this code:
.MousePointer = 0 statementsinto the Form_Paint event procedures. Note that this method will work only when one form is being painted over another. Use the Cut and Paste routines from the Edit menu of Visual Basic. Cut this line of code:
Form1.MousePointer = 0from the event procedure Form_Load in Form1 and paste the code into the Form1 Form_Paint event procedure. Repeat the same Cut and Paste task in Form2, placing the code
Form2.MousePointer = 0in the Form2 Form_Paint event procedure.
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |