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.
Locked
User avatar
celma972
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
Capture.PNG (21.8 KiB) Viewed 2061 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
}

}

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

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

$textbox1_Validated={
if($textbox1.Text){
$button1.Enabled = $true
}else{
$button1.Enabled = $false
}
}
You can also use the TextChanged event to do this.

User avatar
localpct
Posts: 271
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.

Locked