Mulitple forms - proper opening/closing of forms.

DanielB33

Active member
Joined
Mar 29, 2013
Messages
40
Programming Experience
1-3
Thanks for taking your time to read this post.
I open a form from my main application for by the following method:
    Private Sub HoneywellToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles HoneywellToolStripMenuItem1.Click
        Honeywell_Form_Open = True
        If SecondForm.IsDisposed = True Then
            Try
                SecondForm = New Honeywellvb
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        Try
            Me.TopMost = False
            SecondForm.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


And closing form events....
 Private Sub Honeywellvb_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Main.Honeywell_Form_Open = False
        test1_complete = False
        test2_complete = False
        test3_complete = False
        'test4_complete = False
        serial_num_complete = False
        Main.Honeywell_productionSettings(Main.D_MAX_INRUSH_EXTEND) = 0
        Main.Honeywell_productionSettings(Main.D_EXTEND_TIME) = 0
        Main.Honeywell_productionSettings(Main.D_EXTEND_I_AVERAGE) = 0
        Main.Honeywell_productionSettings(Main.D_MAX_INRUSH_RETRACT) = 0
        Main.Honeywell_productionSettings(Main.D_RETRACT_TIME) = 0
        Main.Honeywell_productionSettings(Main.D_RETRACT_I_AVERAGE) = 0
        Main.Honeywell_productionSettings(Main.D_EXTEND_TIME_T2) = 0
        Main.Honeywell_productionSettings(Main.D_RETRACT_TIME_T3) = 0
        Main.Honeywell_productionSettings(Main.D_COMPRESSION_DATAT4) = 0
        Try
            Main.Stop_Honeywell_Fixure_Mode()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Try
            Me.Dispose()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


I am having a strange issue. Whenever I close and re-open the form, I get two message boxes instead of 1. I use many different messageboxes for pass/fail, whenever its the first time I open the form, I get one message box. But if I re-open, I get two! It is really strange. I assume I am creating and disposing of the instance of the form incorrectly. Thoughts? I have spent many hours trying to figure this out with zero success.
 
Last edited by a moderator:
Solved part of the problem out. I use a timer, and I did not dispose the timer on closing events, so I was running my clock interrupt twice (which is where I output a messagebox)
 
If you've added the Timer to the form in the designer then it will be implicitly disposed when the form is. There's no reason to call the form's Dispose method in the FormClosing event handler. If the form was displayed by calling Show then closing it will dispose it. That's not the case if it's displayed by calling ShowDialog but, in that case, it's the caller's responsibility to dispose the form, which would usually be done by having created it with a Using statement in the first place.

You say you've solved part of the problem but not what part and what is still yet an issue.
 
Back
Top