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?
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.
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.
How to enumerate textbox controls on a form?
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
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
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.