recover click event of checkbox

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 2 years and 11 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
Provectio
Posts: 2
Last visit: Fri Apr 09, 2021 6:14 am

recover click event of checkbox

Post by Provectio »

Hello, i am building a form with powershell studio 2021, i have a TextBox with a label : Firstname and another TextBox with a label : Lastname. Then, i have two CheckBoxes, one with a label : FirstName lastName and another one with a label : Lastname FirstName.
i am trying to recover the click event of the checkbox in my script in order to display FirstName lastName or Lastname FirstName
My script :
Switch ($DisplayName)
{
$CheckBox1ADCreaDisplayName_Click { $DisplayName = $GivenName + " " + $Surname }
$CheckBox2ADCreaDisplayName_Click { $DisplayName = $Surname + " " + $GivenName }
}
My problem, when i put only the line 1 of the switch i recover the displayName but when i put the second line i don't recover the displayName. i don't know if anybody can help me ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: recover click event of checkbox

Post by jvierra »

You cannot update a non-glbal variable in a function or event directly. The variable besing accessed is out of scope.

Why would you use two checkboxes to swap and unswap two strings. You can just use on box and check if it is checked.

Code: Select all

if($CheckBox1ADCreaDisplayName.Checked){
           $textbox.Text = $GivenName + " " + $Surname
}else{
          $textbox.Text = $Surname  + " " + $GivenName
}
Provectio
Posts: 2
Last visit: Fri Apr 09, 2021 6:14 am

Re: recover click event of checkbox

Post by Provectio »

Hello jvierra, thank you very much for your help, i just tested with $displayName instead of $textbox.Text and everything is working, I had to try with an if and else but I had put _IsClick instead of .Checked. Thanks again and very good day
This topic is 2 years and 11 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