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 5 years and 10 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.
Hi all,
im having some issues with updating labels of multiple label objects with incremental names: like "labelService1", "labelService2" etc
this is the loop im using but i cant get my head around it to make it work... :
# loading services names from ini file
for ($i = 0; $i -lt $script:ini["ServicesNames"].count; $i++)
{
#these are several attempts i tried to play with... none works :/
#$labelName = '$labelService'+$i
#$labelName.Text = $script:ini["ServicesNames"]["Service$($i)"]
$labelService"$i".text = $script:ini["ServicesNames"]["Service$($i)"]
$labelService$($i).text = $script:ini["ServicesNames"]["Service$($i)"]
("$labelService+$i").text = $script:ini["ServicesNames"]["Service$($i)"]
}
# this is what i actually want to perform:
$labelService0.text = $script:ini["ServicesNames"]["Service0"]
$labelService1.text = $script:ini["ServicesNames"]["Service1"]
$labelService2.text = $script:ini["ServicesNames"]["Service2"]
how can i access an object with a variable in its name? or am i going at it the wrong way?
Hi jvierra
how are you? thank you for your reply!
form.control sounds like the way to do it, i just need to figure out how to access the labels as this does not work..
im trying to write the label's text (initial text is "Service #") to a richtextbox:
This topic is 5 years and 10 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.