Can you add a cls function to clear a text box

Ask your Windows 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.
Locked
User avatar
daviesg6
Posts: 49
Joined: Thu Nov 21, 2013 12:36 pm

Can you add a cls function to clear a text box

Post by daviesg6 » Thu Feb 06, 2014 9:21 am

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: 13882
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Feb 06, 2014 9:39 am

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
Joined: Thu Nov 21, 2013 12:36 pm

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

Post by daviesg6 » Thu Feb 06, 2014 9:53 am

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: 13882
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Feb 06, 2014 10:02 am

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.

Locked