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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
StupidSexyFlanders
Posts: 107
Joined: Sun Nov 27, 2011 9:22 am

One Click to rule them all?

Post by StupidSexyFlanders » Tue Oct 09, 2012 12:11 pm

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
Joined: Thu Aug 18, 2011 4:56 am

One Click to rule them all?

Post by davidc » Wed Oct 10, 2012 4:28 am

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.