Make a text box mandatory

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 5 years and 4 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
Chris_Ediger
Posts: 45
Last visit: Tue May 09, 2023 8:35 pm

Make a text box mandatory

Post by Chris_Ediger »

I would like to make a text box in my script mandatory. As in the "OK" button will not work unless the box has something in it.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Make a text box mandatory

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Chris_Ediger
Posts: 45
Last visit: Tue May 09, 2023 8:35 pm

Re: Make a text box mandatory

Post by Chris_Ediger »

Can you maybe tell me where you moved this post?
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Make a text box mandatory

Post by Alexander Riedel »

Right here where you answered it :D In the PowerShell GUI forum.
Alexander Riedel
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: Make a text box mandatory

Post by jvierra »

Here is a good place to start to learn how to validate a form based on its contents. There are a number of techniques described and some very good examples.

https://info.sapien.com/index.php/guis/gui-advanced-tips/validating-the-form

Since you are new to forms I recommend reading some of the other articles listed in the left menu. They will help you get up to speed with forms fairly quickly.

The simple answer to your question is to use the textbox "Validating" event to cancel the button event. The exact method of validation is a design choice which depends on the form design you are using.
This topic is 5 years and 4 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