Forms that act unexpectedly

I will try to explain this in the best possible way.

I have a windows application that contains numerous forms. The first form to open is a non-modal form that acts as a command form for issuing various formats to the main backup program. The second form opens, which is basically my Main Form for the application. This form contains several checkboxes to run methods that make changes to the backup program. This form is also unnecessary. Each box that is checked at the same time and executes methods to delete, modify and add to res. Different boxes can be checked at any given time. Below is the code for check boxes:

Private Sub frmOWTMain_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp

    If e.KeyCode = Keys.Enter Then
        Me.Hide()  'here i want to hide the OWTMain form
        Call ckforPNR()
        If Me.cbPricing.Checked Then
            Call doPricing()
            Me.cbPricing.Checked = false
        End If
        If Me.cbUdids.Checked Then
            frmUdids.Show()
            Me.cbUdids.Checked = False
        End If
        If Me.cbMod.Checked Then
            Call doModUdids()
        End If
        If Me.cbFare.Checked Then
            Call doFareSavings()
            Me.cbFare.Checked = False
        End If
    End If
    Me.show()  'This is the problem. This runs during method calls. All I'm
       'looking to do is re display the OWTMain form.   
End Sub 

      

At this point, I want to display the OWTMain form above again. This is where I have a problem. As you can see, a number of methods are called which involve displaying other forms to the user. I do NOT want any of these forms to be modal, because I want the original first open form to still be able to issue commands to the res program to view the information other forms need.

Here's an example of some method calls:

Private Sub doPricing()
    Dim myPrice As New Pricing   'a call to another class that handles pricing
    If myPrice.getTQT = False Then
        frmAddPricing.ShowDialog()  'showing new forms
    Else
        frmCurPricing.ShowDialog()
    End If
End Sub

Private Sub doFareSavings()
    Dim myPrice As New Pricing
    If myPrice.checkForFS = False Then
        frmFS.ShowDialog()  'showing new forms
    End If
    If myPrice.checkForFS = True Then
        frmFSVerify.ShowDialog()
    End If
End Sub

      

When I call any of these methods, the OWTMain form is shown prematurely, while the other forms from the called method still work. I expected the code at the top to run in call order, but it doesn't. I just want to display OWTMain forms after running all the code. I haven't been able to figure this out without writing a ton of code to minimize opening and closing windows.

Any help with this would be greatly appreciated. Thank. John

+3


source to share


1 answer


This will check if all subforms are closed and then redisplay the main form.

remove exitsing me.show ()

Public Sub ReShowMainForm()
    ' add all sub forms to this check
    if frmFS.Visible = false andalso 
       frmUdids.Visible = false andalso
       frmFSVerify.Visble = false then 
      Me.Show
    End If
End Sub

      



modify xyzForm.Show xyzForm.Show (me) to make the main form available as a parent of the subforms.

Handle the FormClosed event on each additional form and add the following code

DirectCast( me.parent, frmOWTMain).ReShowMainForm()

      

0


source







All Articles