find function word processor

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

i am creating a word processor in c# and would like to know 2 things:

1. in my separate find form, how do i acess a richtextbox in my main form
(form1)?

2. i know the code to find stuff e.g.

richtextbox1.find(searchtermsbox.text);

but if you click the find button with this code at its onclick event, it
will only find the first time the text appears. what code do i need for a
button that finds all of the recurrances of the text e.g. a find next button?
 
Alvo said:
hi,

i am creating a word processor in c# and would like to know 2 things:

1. in my separate find form, how do i acess a richtextbox in my main form
(form1)?

2. i know the code to find stuff e.g.

richtextbox1.find(searchtermsbox.text);

There are several overloads of find. One uses the text only, one takes
an integer as the second argument, which is the position to start
searching from.

int pos = 0;

for ( int i=0; i<3; ++i )
pos = richtextbox1.find( searchtermsbox.text, pos+1 );

for example, will find the 3rd occurrence.

Matt
 
hi,

thanks for the answer. by the way, would you happen to know the answer to my
first question: in my separate find form, how do i acess a richtextbox in my
main form (form1)?
 
Not unlike the source viewer you were making for your web browser, your best
bet would be to expose a property from the form containing the RichTextBox
that is accessible via the reference to the containing form from the calling
code.

Brendan
 
Alvo said:
hi,

thanks for the answer. by the way, would you happen to know the answer to my
first question: in my separate find form, how do i acess a richtextbox in my
main form (form1)?

You have two choices.

1) Make the richtextbox a public variable in form1:

public class Form1
{
public RichTextBox richtextbox1; // Change from private.
}

2) Make it a property of the form:

public class Form1
{
private RichTextBox richtextbox1;

public RichTextBox RichText // Or whatever you want to call it.
{
get { return richtextbox1; }
}
}

Then just use it from another form:

public class Form2 : Form
{
void function()
{
// Case 1: public variable
Form1.richtext1.<whatever>
// Case 2: property
Form1.RichText.<whatever>
}
}

Matt

}
}
 
Back
Top