Hey. Ok so i'm having a problem in my program, so instead of trying to find the bug right away, I decided to test the problem that I'm having by creating a new basic program with two forms. It seems that if I make a new instance of a form, and don't set it to visible, then that form won't run the .closing method. Here's what I did:
Form1- contains 1 button
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If f2 Is Nothing Then f2 = New Form2 End If End Sub
form 2
- contains 1 timer
- modified .closing method
VB Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick MsgBox("time to run the closing code") Me.Close() End Sub
VB Code:
Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed MsgBox("doing the actual closing now!") Me.Dispose() f2 = Nothing End Sub
Module
VB Code:
Friend Module DuckyModule Friend f1 As Form1 ' can now be accessed from anywhere. Friend f2 As Form2 End Module
Ok so, the timer is designed to within 5 seconds close form2 when it starts. If I don't do anything about seting the form visible (like .showDialog) then when the timer calls .close() then nothing happens! If I put in .setDialog() then the when the timer calls .close() then it works!. Is this normal? Any ideas on what I could do?
Thanks
John




Reply With Quote