Why is my form remembering?

989
14
Jump to solution
01-22-2014 10:20 AM
deleted-user-VeC5jUIlNXtq
Occasional Contributor III
Hey all,

I have an Add-In where the user browses to a FGDB (returns a string of the FGDB path and adds it to a label on the form). I have another label that has the string of a file path, and then 2 combo boxes (choose a layer).

The user is unable to proceed unless all parameters are filled out, so if they navigate to a FGDB, but forget to add the required layers, they close the form, add the data, and re-open the form.

EDIT: "Close the form" = stop the Add-in, add the data, then re-launch the add-in.

However, my form is remembering the file paths (they're also stored in a public string variable).

My question is, what am I doing incorrectly about closing the form and not disposing (?) of all the variables. The combo boxes are cleared, but the variables and the labels which store the paths remain intact.

Here's the code for the form:

Public Class frmProgress      Private Sub btnBrowseGPX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseGPX.Click         Call Procedures.GetGPXPath()     End Sub      Private Sub btnBrowseGDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseGDB.Click         Call Procedures.GetGDBPath()     End Sub      Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click         ' Close the form, but continue with the code in Procedures.         Me.Hide()         bContinue = True     End Sub      Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click         ' Exit the Do loop in Procedures using the continue boolean and close the form.         bContinue = False         Me.Close()     End Sub      Private Sub frmProgress_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing         If e.CloseReason = Windows.Forms.CloseReason.UserClosing Then             bContinue = False             e.Cancel = False         End If     End Sub End Class


The program has a Do loop so that if they attempt to proceed without filling out the parameters, it will get mad, but keep the form open. Thus the reason for the Me.FormClosing handle.

Anyways, I'm going to review some other Add-Ins I have which have similar functionality, I'm sure it's just a small oversight, but if you can think of anything of the bat, that would be greatly appreciated!
0 Kudos
14 Replies
KenBuja
MVP Esteemed Contributor
When I have a form with required parameters, I disable the OK button until everything required is fill out. Each control that is required runs a subroutine on its Click (or KeyPress or Changed etc) event that checks if all requirements have been met. If so, the button is enabled. Here's an example

    Private Sub EnableRun()

        If cboLayers.Text <> "" Then
            If chkCreate.Checked Then
                If txtIntersection.Text <> "" Then
                    btnOK.Enabled = True
                Else
                    btnOK.Enabled = False
                End If
            Else
                btnOK.Enabled = True
            End If
        Else
            btnOK.Enabled = False
        End If

    End Sub

    Private Sub chkCreate_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCreate.CheckedChanged
    
        'do something 

        EnableRun()

    End Sub

    Private Sub txtIntersection_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtIntersection.TextChanged

        'do something 

        EnableRun()

    End Sub
0 Kudos
deleted-user-VeC5jUIlNXtq
Occasional Contributor III
All four components are required.

They pick the output geodatabase, choose the two layers as required, and pick a .gpx file, then hit OK.

The rest of code runs without user input. I wanted to get it all out of the way in one area.
0 Kudos
deleted-user-VeC5jUIlNXtq
Occasional Contributor III
When I have a form with required parameters, I disable the OK button until everything required is fill out. Each control that is required runs a subroutine on its Click (or KeyPress or Changed etc) event that checks if all requirements have been met. If so, the button is enabled. Here's an example


That's a great idea...thanks for the information!
0 Kudos
LeoDonahue
Occasional Contributor III
Like I said, and like Mr. Buja shows with his example, your Ok and window closing events can call a routine that checks whether your parameters have been filled out.  filled out vs filled out right is a different story.
0 Kudos
deleted-user-VeC5jUIlNXtq
Occasional Contributor III
Great, thanks very much guys. Appreciate the information!
0 Kudos