enable button if $texbox not empty

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 3 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
celma972
Posts: 3
Last visit: Fri Feb 18, 2022 6:43 am

enable button if $texbox not empty

Post by celma972 »

Dear All,

I cannot figure out how to enable a button when the $loginnametextbox is not empty. It stay disable.
Capture.PNG
Capture.PNG (21.8 KiB) Viewed 2985 times
Here i my code :

$loginametextbox.Text = $null

$formEnableUsersForm_Load={
#TODO: Initialize Form Controls here
$buttonOK.Enabled = $false
}

$buttonOK_Click={
#TODO: Place custom script here
$buttonOK.Enabled = $false

$loginametextbox.Text= {
$CheckInput
}

If ($CheckInput.text.trim() )
{
$buttonOK.Enabled = $true
}

}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: enable button if $texbox not empty

Post by jvierra »

Use the validation event to set that when the textbox is update.
  1. $textbox1_Validated={
  2.     if($textbox1.Text){
  3.         $button1.Enabled = $true
  4.     }else{
  5.         $button1.Enabled = $false
  6.     }
  7. }
You can also use the TextChanged event to do this.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: enable button if $texbox not empty

Post by localpct »

On to J's point, textchanged event is great if you have a predetermined number of characters and you can eliminate the button if you choose.
This topic is 7 years and 3 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