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.
Locked
User avatar
Chris.Ediger
Posts: 26
Joined: Tue Oct 24, 2017 9:33 am

Make a text box mandatory

Post by Chris.Ediger » Thu Nov 08, 2018 2:38 pm

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: 7098
Joined: Tue May 29, 2007 4:43 pm

Re: Make a text box mandatory

Post by Alexander Riedel » Thu Nov 08, 2018 2:51 pm

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
Chris.Ediger
Posts: 26
Joined: Tue Oct 24, 2017 9:33 am

Re: Make a text box mandatory

Post by Chris.Ediger » Thu Nov 08, 2018 3:18 pm

Can you maybe tell me where you moved this post?

User avatar
Alexander Riedel
Posts: 7098
Joined: Tue May 29, 2007 4:43 pm

Re: Make a text box mandatory

Post by Alexander Riedel » Thu Nov 08, 2018 3:20 pm

Right here where you answered it :D In the PowerShell GUI forum.
Alexander Riedel
SAPIEN Technologies, Inc.

jvierra
Posts: 13891
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Make a text box mandatory

Post by jvierra » Thu Nov 08, 2018 4:25 pm

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.

Locked