I have an 'Apply' button on a form which initially has the property Enabled = False, but when a control within any GroupBox on the from is changed Enabled = True should be set.
I have several GroupBox controls on the form, and I was hoping that I could simply check if a control within any of these had changed. However, while it seems you can hook to the ControlAdded and ControlRemoved events, there is no ControlChanged event.
So I'm currently setting this up as below (there are a lot more than 5 controls to check in reality).
Is there a more efficient way of doing this, as I can see this causing issues in the future (if options are ever added to a Group for example)? Thanks.
Private Sub ControlChanged(sender As Object,
e As EventArgs) Handles txtUsername.KeyUp,
chkRestoreIEFavourites.CheckedChanged,
chkRestoreNicknames.CheckedChanged,
chkRestoreDesktop.CheckedChanged,
chkRestoreQuickLaunch.CheckedChanged
Me.btnApply.Enabled = True
End Sub
Alas, I've figured out a way of doing this...
The below now adds handlers (on
Shown) so that if anyCheckBoxorTextBoxwithin aGroupBoxon the form is changed, theApplybutton is set toEnabled = True. I also remove the handles when the from isClosing.Whether this is the best way of doing it I don't know, but for now it's the only way that I know. Comments welcome!
Note that you will need to import
System.LinqandSystem.Windows.Formsto use this solution.