Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning/Afternoon

I am trying to create a search box that search for any control that is in my WinForm, for a example if you typed email address into the search box it would scan through the project WinForm and anything that does not contain the word the word email it would set the visible state to false but buttons, labels, textbox etc that contains the word email would stay true. I am very new to coding so right now i am clueless on how to do this. If someone could point me in the right direction on how to do this or any articles that contains any information or code snips on how to do this that be great, thank you.

What I have tried:

So far I have not tried anything has I am still new to this and just looking for guidance on how to complete this.
Updated 15-Mar-23 5:16am

1 solution

You would need to recursively run through the Controls Collection which every Control has - including a Form because they are derived from the base Control class.

You can then check each Control.Text property to see if the text is there.
Do be aware that Labels (which instruct the user where to enter an email) are separate Controls from the TextBox the user types in - so unless the TextBox also contains the text it will be hidden.
If that is not what you intended, you might want to consider using the Tag property of each control to either "tie together" controls, or to give you somewhere else to search!
Share this answer
Ralf Meier 15-Mar-23 13:54pm    
Hi Griff,
your answer is, as everytime, quiet correct ... but I suppose that it isn't useful for the OP because there are a lot of basics missing ...
OriginalGriff 16-Mar-23 3:20am    
Could be - but it at least tells him what he needs to learn (and it's pretty basic stuff!) :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900