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.
User avatar
Posts: 3
Joined: Sat Sep 17, 2016 9:59 am

enable button if $texbox not empty

Post by celma972 » Fri Dec 16, 2016 4:07 am

Dear All,

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

$loginametextbox.Text = $null

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

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

$loginametextbox.Text= {

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


User avatar
Posts: 13681
Joined: Tue May 22, 2007 9:57 am

Re: enable button if $texbox not empty

Post by jvierra » Fri Dec 16, 2016 5:33 am

Use the validation event to set that when the textbox is update.

Code: Select all

$button1.Enabled = $true
$button1.Enabled = $false
You can also use the TextChanged event to do this.

User avatar
Posts: 285
Joined: Wed Sep 09, 2015 12:53 pm

Re: enable button if $texbox not empty

Post by localpct » Sat Dec 17, 2016 12:55 am

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.