禁用父控件的所有控件

时间:2015-03-26 20:23:37

标签: vb.net vb.net-2010

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

0 个答案:

没有答案