Find Functionality
- How can I add a control / menu / etc that enables find functionality? I have a text box populated with the contents of a text file. I'd like to give the user the ability to search that text box.
- Moved byOmegaManMVPWednesday, July 01, 2009 9:01 PM (From:Visual C# General)
Answers
- This worked for me:
string textToFind = "is"; int findPosition = textBox2.Text.IndexOf(textToFind); textBox2.Focus(); textBox2.SelectionStart = findPosition; textBox2.SelectionLength = textToFind.Length;You would just need to set textToFind to whatever the user typed in.
Hope this helps.
www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!- Marked As Answer byJay Mazz Wednesday, July 01, 2009 9:03 PM
All Replies
- How did you want it to work? Just move the focus to the found text?
www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! - Yes, highlighting would be great but isn't necessary.
- This worked for me:
string textToFind = "is"; int findPosition = textBox2.Text.IndexOf(textToFind); textBox2.Focus(); textBox2.SelectionStart = findPosition; textBox2.SelectionLength = textToFind.Length;You would just need to set textToFind to whatever the user typed in.
Hope this helps.
www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!- Marked As Answer byJay Mazz Wednesday, July 01, 2009 9:03 PM
- I have a menu strip to which I added 'Find'. When I click 'find', I'd like to pop open an input box (which I'll use to set textToFind). How can I pull that off?
- You can make your own Search Form for that.
Anyways, you may want to add this de Deborah's answer:
textBox2.ScrollToCaret();
I always try to Keep it Sharp & simple. - Here is an example of an input box:
http://www.csharp-examples.net/inputbox/
Otherwise, you could just add a second TextBox to your form that displays the Text and have a Search button. Then it would look more like IE's search.
www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!


