One Click to rule them all?

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
StupidSexyFlanders
Posts: 107
Last visit: Thu Apr 29, 2021 8:47 am

One Click to rule them all?

Post by StupidSexyFlanders »

As soon as my form loads it immediately checks the users current domain. If it's not an approved domain, all the form controls are disabled. Currently, I am doing an IF($ENV:USERDOMAIN -ne 'mydomain') and them manually enabling/disabling all the controls based on the results.

Is there a command that I can invoke that can set *all* the controls (or at least all the buttons) to 'Enabled = $false' ? I was thinking of adding all my control names to an array, and them doing a foreach...but i don't know if that's the best way (or even possible).

Thanks
Mike
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

One Click to rule them all?

Post by davidc »

First you must forge a function in the depths of Mount Doom that will iterate through all the controls and disable/enable them:

function Enable-Controls
{
param([bool]$Enabled, [System.Windows.Forms.Form]$Form)
foreach($control in $Form.Controls)
{
$control.Enabled = $Enabled
}
}

After you have forged this one function to disable them all you must wield it as thus:

Enable-Controls $false $form1

Note: Disabling the container control and it will disable all its children. For example, disabling a Groupbox will disable all the control contained within. You do not want to disable the form itself because the all windows system buttons such as the close X button will not work.

David

[PS. With a title like that you are just asking for a response like this ;-)]
David
SAPIEN Technologies, Inc.
This topic is 11 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.