get list of a specific control in my GUI

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

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 1 year and 6 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.
Locked
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

get list of a specific control in my GUI

Post by Domtar »

hi all,

I have multiple groupBoxes that are visible or not depending on some selection done in the GUI. Instead of coding each groupBox and set them as visible or not, i was wondering if there was a way to get all those groupBoxes, like in (pseudo-code to illustrate)

foreach ($group in $form.groupBox){
if ($group.name -eq $nameOfGroup) {
$group.visible = $true}
else {
$group.visible = $false
}
}

thanks!
by jvierra » Wed Sep 07, 2022 3:23 pm

Code: Select all

$form.Controls | Where-Object{ $_.GetType().Name -eq 'GroupBox'}
Go to full post
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: get list of a specific control in my GUI

Post by jvierra »

Code: Select all

$form.Controls | Where-Object{ $_.GetType().Name -eq 'GroupBox'}
This topic is 1 year and 6 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.
Locked