User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

The Enable property is shared by all WinForms controls. This property allows you to disable controls so they no longer can be interacted with.

For example, after pressing a button that triggers a Job, it is necessary to disable the button in order to prevent the user from pressing it again until the Job completes. Some instances might require you to disable a group of controls. In this case, your code may look like the following:

$buttonAdd.Enable = $false
$buttonRemove.Enable = $false
$comboBoxOptions.Enable = $false

This list of controls can get rather long, especially when working with a large group of controls.

The good news is WinForms provides an easy alternative for disabling a group of controls and this can be accomplished by using container controls. A container control is a control that allows you to place other controls within it. Examples of container controls include:

GroupBox
Panel
TabControl
TableLayoutPanel

 

Once you have decided which container control to use, simply place all the controls you wish to enable / disable within the container. In this case I used a GroupBox to group my controls:

GroupBox of Controls

Now when you need to disable the controls, you simply set the GroupBox’s Enable property to False and all the controls contained within will be disabled.

$buttonDisableGroup_Click={
    $groupbox1.Enabled = $false
}

Disabled Groupbox

WARNING: It is not recommended using the Form’s Enable property. Doing so will result in an unresponsive window and will prevent you from interacting with the GUI. In other words, you will not be able to move, resize, or exit the form.

You can download the Enable and Disable Controls Sample here.

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.
Copyright © 2024 SAPIEN Technologies, Inc.