|
-
Oct 31st, 2007, 12:13 AM
#1
Thread Starter
New Member
[RESOLVED] [2005] Form load event not firing as expected
I'm having a problem with a form load event not firing when I create a new instance of a form. I'm sure I'm probably missing something really simple, but I just can't seem to see it. Please ignore the purpose of this project as it is merely a simple demonstration of behavior I have run into in a much more complex project.
Setup: One form (frmTest) containing a text box (txtTest), a "New Form" button (cmdNewForm), and an "Exit" button (cmdExit).
Code:
Public Class frmTest
Private Sub frmTest_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call MsgBox("Loading...")
End Sub
Private Sub cmdNewForm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNewForm.Click
Dim frmNew As New frmTest
Call MsgBox("Test 1")
frmNew.txtTest.Text = "Test"
Call Me.Hide()
Call MsgBox("Test 2")
Call frmNew.ShowDialog()
frmNew = Nothing
Call Me.Show()
End Sub
Private Sub cmdExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdExit.Click
Call Me.Close()
End Sub
End Class
Expected behavior: Upon clicking the "New Form" button, a new instance of frmTest should be created, causing the frmTest.Load event to fire so that the msgbox pops up with "Loading...", followed by "Test 1" and "Test 2".
Observed behavior: Clicking the "New Form" button appears to create a new instance ("Test" appears in the text box when shown), but the order of the msgboxes is "Test 1" then "Test 2" and finally "Loading..." Thus it appears that the form load event is not being triggered until ShowDialog() is called.
Any suggestions? I tried removing the form load event and re-inserting it as that seemed to solve an issue in a different thread, but it didn't work for this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|