Reputation: 115
I have a set of controls on my form and i want to enable/disable some of them. what is the best way? Hint: I don't want to change all controls available in my form.
Upvotes: 0
Views: 40
Reputation: 32445
If you want change controls outside of form, then create a public property or method which do it, instead of making controls public
Public Class MyForm
Inherits Form
Private _MyCheckBoxControl As CheckBox
Private _MyTextBoxControl As TextBox
Private _IsGroupOfControlsEnabled As Boolean
Public Property IsGroupOfControlsEnabled As Boolean
Get
Return _IsGroupOfControlsEnabled As Boolean
End Get
Set (value As Boolean)
_IsGroupOfControlsEnabled = value
'Update controls
_MyCheckBoxControl.Enabled = _IsGroupOfControlsEnabled
_MyTextBoxControl.Enabled = _IsGroupOfControlsEnabled
End Set
End Class
Upvotes: 0
Reputation: 577
If your meaning from "enable/disable" is "preventing user from changing them", then you can do this:
THE_NAME_OF_CONTROL.Enabled = False 'Disable a control with THE_NAME_OF_CONTROL Name
And
THE_NAME_OF_CONTROL.Enabled = True 'Enable a control with THE_NAME_OF_CONTROL Name
Or you can put all of your controls in a "Group Box" and disable/enable whole group box.
Upvotes: 1