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
Solved! Go to Solution.
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
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