更改控件集特定属性的最佳方法 VB.net



我的窗体上有一组控件,我想启用/禁用其中的一些控件。 最好的方法是什么?提示:我不想更改窗体中可用的所有控件。

如果您从"启用/禁用"中的意思是"阻止用户更改它们",那么您可以这样做:

THE_NAME_OF_CONTROL.Enabled = False 'Disable a control with THE_NAME_OF_CONTROL Name

THE_NAME_OF_CONTROL.Enabled = True 'Enable a control with THE_NAME_OF_CONTROL Name

或者,您可以将所有控件放在"分组框"中,然后禁用/启用整个分组框。

如果要在窗体之外更改控件,请创建一个公共属性或方法来执行此操作,而不是使控件公开

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

相关内容

最新更新