Hello!
In my application, there is a richtextbox, a text file will be imported to it.
The richtextbox is read only....
Now I want to add the "Find(Ctrl+F)" function to it as a text file...However, I did not know how to implement that.
Any idea
Thanks!

How to offer "Find(Ctrl+F)" function to a richtextbox?
a.d.m
I guess implement the richtextbox keydown event (or maybe form) and check to see if the keys pressed is Control and F and if so then pop up a search box or something. For the sake of simplicity lets just enable/visible a textbox on the same form
private void richTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.Keys == Keys.F)
{
this.theTextBox.Visible = true;
}
else
{
this.theTextBox.Visible = false;
}
}
now we enter text in the textbox and when we press "search" for example, it will go through the RTB control and try to find that word. How to do it is up to you. you could go through line by line in the Lines[] string array of the RTB and check to see if in there contains the word they are searching and if so then select it but you may want to set a global variable to indicate the current position you were searching on (then reset it later) so that you dont end up with the search being on the last line for example (so they keep pressing find next until no more lines left)
just an idea but hope it helps
NoobestNoob
I will try to work it out :)
joynerCN
no worries!
another thing to add in terms of the search functionality is to use Regex (regular expressions). Regex is designed for this purpose but tricky to learn. The problem maybe on locating the actual word to select/highlight it when using regex, im not sure. Just throwing in other possibilities!