Checking if a text box is 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 9 years and 1 month 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
the_ratzenator
Posts: 5
Last visit: Tue Mar 10, 2015 10:55 am

Checking if a text box is empty

Post by the_ratzenator »

I would like to know how I can tell PowerShell Studio to be able to display a message if a text box is empty after the user presses on a Run button, or is there a way within the Designer to make values in a text box mandatory?

Thanks
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Checking if a text box is empty

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, the_ratzenator.

Did you remember to include the following?
  • 1. Product, version and build (e.g. Product: PowerShell Studio 2014, Version & Build: 4.1.71. Version and build information can be found in the product's About box accessed by clicking the blue icon with the 'i' in the upper right hand corner of the ribbon.)
    2. Specify if you are running a 32 or 64 bit version
    3. Specify your operating system and if it is 32 or 64 bit.
    4. Attach a screenshot if your issue can be seen on the screen
    5. Attach a zip file if you have multiple files (crash reports, log entries, etc.) related to your issue.
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Checking if a text box is empty

Post by davidc »

I moved this post to the PowerShell GUI questions.

You can do a simple check in your button click event:
PowerShell Code
Double-click the code block to select all.
$button1_Click={
	#TODO: Place custom script here
	if ($textbox1.TextLength -eq 0)
	{
		$form1.DialogResult = 'None' #cancel close if button is using DialogResult
		return
	}
	
	
}#end button1_Click
Alternatively you can look at validation:

http://www.sapien.com/blog/2011/09/02/primalforms-2011-validating-the-form-part-1/

David
David
SAPIEN Technologies, Inc.
This topic is 9 years and 1 month 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