Rich Text box question

B

Brad Allison

Hi,

I guess I am not understanding something and I have been searching Help in
VB, newgroups, etc.

I have a simple application that contains just over 300 rich text files
(these are breed standards for purebred dogs). The user selects the breed
from a Tree View and based on this selection, the appropriate rtf file is
opened in a different form containing the rich text box control. All of
this works so here comes my dilemma...

I want to user to have the capality to search the opened file using a
keyword or words and the rtf to highlight and go right to the found text. I
know enough to use rtf.find(), but this returns an integer and from there I
do not know where to go.

The next thing I want to do is have the capability to find all files that
contain the specific keyword. I would imagine that I have to open each file
(one at a time) into a streamreader and do a search from there. If the
keyword is found then I can add that file to a listbox.

Thank you for any useful information.

Brad
 
J

Juan Romero

I am just talking out of my head here, but If I remember well, the Find
Function returns the integer corresponding to the index of the first
character of the search match, so what you want to do is set the selection
start point to that index, call the ScrollToCaret [or something like that]
method to make the box scroll to the item found, then select or highlight
the whole word (which goes beyond the scope of this explanation).

Good Luck!
 
B

Brad Allison

I am getting the index of each occurence of the string that is found, but I am still unsure as to how to set the selection start point. I am even arbitrarily setting a high integer as a faux starting point and the running the ScrolltoCaret method:

rtbView.SelectionStart = 5000
rtbView.ScrollToCaret()

This is still not doing anything. Any help will be appreciated.

Brad

Juan Romero said:
I am just talking out of my head here, but If I remember well, the Find
Function returns the integer corresponding to the index of the first
character of the search match, so what you want to do is set the selection
start point to that index, call the ScrollToCaret [or something like that]
method to make the box scroll to the item found, then select or highlight
the whole word (which goes beyond the scope of this explanation).

Good Luck!

Brad Allison said:
Hi,

I guess I am not understanding something and I have been searching Help in
VB, newgroups, etc.

I have a simple application that contains just over 300 rich text files
(these are breed standards for purebred dogs). The user selects the breed
from a Tree View and based on this selection, the appropriate rtf file is
opened in a different form containing the rich text box control. All of
this works so here comes my dilemma...

I want to user to have the capality to search the opened file using a
keyword or words and the rtf to highlight and go right to the found text. I
know enough to use rtf.find(), but this returns an integer and from there I
do not know where to go.

The next thing I want to do is have the capability to find all files that
contain the specific keyword. I would imagine that I have to open each file
(one at a time) into a streamreader and do a search from there. If the
keyword is found then I can add that file to a listbox.

Thank you for any useful information.

Brad
 
J

Juan Romero

He he he,

As I was reading your postback, I was trying to remember, since I knew I had
come to this problem too....
Well, here is the answer, all you need to do is call:

rtb1.find("mysearchstring")

BUT! (here is the trick...)

Give the Richtextbox control the focus after that, and it will magically
highlight the word....

rtb1.focus()

Why it behaves this way? who knows...

I am getting the index of each occurence of the string that is found, but I
am still unsure as to how to set the selection start point. I am even
arbitrarily setting a high integer as a faux starting point and the running
the ScrolltoCaret method:

rtbView.SelectionStart = 5000
rtbView.ScrollToCaret()
This is still not doing anything. Any help will be appreciated.
Brad
Juan Romero said:
I am just talking out of my head here, but If I remember well, the Find
Function returns the integer corresponding to the index of the first
character of the search match, so what you want to do is set the selection
start point to that index, call the ScrollToCaret [or something like that]
method to make the box scroll to the item found, then select or highlight
the whole word (which goes beyond the scope of this explanation).

Good Luck!

Brad Allison said:
Hi,

I guess I am not understanding something and I have been searching Help in
VB, newgroups, etc.

I have a simple application that contains just over 300 rich text files
(these are breed standards for purebred dogs). The user selects the breed
from a Tree View and based on this selection, the appropriate rtf file is
opened in a different form containing the rich text box control. All of
this works so here comes my dilemma...

I want to user to have the capality to search the opened file using a
keyword or words and the rtf to highlight and go right to the found
text.
I
know enough to use rtf.find(), but this returns an integer and from
there
I
do not know where to go.

The next thing I want to do is have the capability to find all files that
contain the specific keyword. I would imagine that I have to open each file
(one at a time) into a streamreader and do a search from there. If the
keyword is found then I can add that file to a listbox.

Thank you for any useful information.

Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top