Page 1 of 1
How to enumerate textbox controls on a form?
Posted: Tue Feb 05, 2013 4:54 am
by rtiel1
How can I enumerate all textboxes on a form? I want to clear all textboxes on a form with one click without having to specify each control. When I use eg $testform.Controls it returns only buttons, groupboxes etc but no text- or comboboxes. I'm using Powershell Studio 2012 latest version.
Thnx Remco
How to enumerate textbox controls on a form?
Posted: Tue Feb 05, 2013 5:06 am
by davidc
The Controls property only contains the direct child controls. So if the textboxes are located in a group box or any other container control, then you will need to use the groupbox's Controls property instead.
foreach($control in $groupBox.Controls)
{
if($control -is [System.Windows.Forms.TextBox])
{
$control.Enabled = $false
}
}
Note: You can tell that a control is a container by using the following:
if( $control -is [System.Windows.Forms.ContainerControl])
....
David
How to enumerate textbox controls on a form?
Posted: Tue Feb 05, 2013 5:11 am
by rtiel1
Thnx for the explanation, another thing learned today