Public Sub disableControls(parent As Control, Optional ByVal disable As Boolean = True)
For Each child As Control In parent.Controls
ClearControls(child)
Next
If disable = True Then
TryCast(parent, TextBox).Enabled = False
TryCast(parent, ComboBox).Enabled = False
TryCast(parent, DateTimePicker).Enabled = False
TryCast(parent, Button).Enabled = False
Else
TryCast(parent, TextBox).Enabled = True
TryCast(parent, ComboBox).Enabled = True
TryCast(parent, DateTimePicker).Enabled = True
TryCast(parent, Button).Enabled = True
End If
End Sub
需要帮助,我在NullReferenceException was unhandled
TryCast(parent, TextBox).Enabled = False
了