Can you add a cls function to clear a text box

Ask your PowerShell-related questions, including questions on cmdlet development!
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 10 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
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Can you add a cls function to clear a text box

Post by daviesg6 »

I would like to add a button to a form that clears the contents of a text box, a bit like using cls to clear the clutter from a powershell window.
Does anyone know how to code this?

The form was created using primalforms, in the form search results are piped to the text box which is read only to the user. I would like to give users the ability to clear previous results before performing the next search
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Can you add a cls function to clear a text box

Post by jvierra »

I recommend reading the blog here. It has an excellent tutorial on how to design GUIs and plenty of info on how controls work.

http://www.sapien.com/blog/topics/user- ... istrators/
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Can you add a cls function to clear a text box

Post by daviesg6 »

I had already looked at that, it's very useful but doesn't give any pointers to the specific function I want to add here.
What I want is not a mission critical requirement but a nice to have option so users can clear what is displayed before performing another search so it is easier for them to read their results. It may become a requirement later as there is the possibility it will be used by people with access to sensitive information who will need the ability to quickly hide what is on their screen
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Can you add a cls function to clear a text box

Post by jvierra »

What I am trying to do is to get you to look at how we design GUI forms. You are asking questions and thinking like you are using a command prompt. Forms are not like that.

When you do a new query and assign the results to the control it will replace the results in the control. It does not add to the control unless you are specifically requesting that it be added.

You should spend time reading and trying the examples in the blog and the related articles under "Spotlight on Controls".

There is no equivalent of cls in Forms. You can write a function to clear all controls as needed. Remember that "clear" is a concept that applies to a form. CLS is a command that applies to a console screen.

You can code a loop over the Forms.Controls collection and clear ach control in the loop but you have to only clear controls that actually have content. Buttons do not have content.
This topic is 10 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