CHeck not disabling textbox

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 7 years and 2 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
Synntax
Posts: 4
Last visit: Tue Jan 17, 2017 10:52 am

CHeck not disabling textbox

Post by Synntax »

Simple just trying to get the textbox to disable if my checkbox is checked.

$NE_CheckedChanged={
#TODO: Place custom script here
IF ($NE.CheckState -eq 'Checked'){
$textbox1.Enabled = $false
}
else {
$textbox1.Enabled = $true
}
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: CHeck not disabling textbox

Post by DevinL »

Instead, try looking for $NE.Checked like so:
  1. $checkbox1_CheckedChanged = {
  2.   if ($checkbox1.Checked -eq $true) {
  3.     $textbox1.Enabled = $false
  4.   } else {
  5.     $textbox1.Enabled = $true
  6.   }
  7. }
DevinL
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: CHeck not disabling textbox

Post by jvierra »

This is actually the easiest way to use a Boolean to assign a Boolean::
  1. $checkbox1_CheckedChanged = {
  2.     $textbox1.Enabled = $checkbox1.Checked
  3. }
This is one of many reasons why "Forms" is so easy to program when you understand the design paradigm and how well done object and event design can simplify coding.
This topic is 7 years and 2 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