If I am understanding correctly, you want to implement something like the find dialog in notepad. Is that correct?
If so, it sounds like you're trying to go about this in a weird way.
I assume you've created the form to do the finding or whatever it's doing. Change the constructor to include a
RichTextBox
ie...
public FindForm(RichTextBox TextBoxToSearch)
{
...
}
Here's an example that I just tested:
public partial class find : Form
{
private RichTextBox _textBoxToUse;
public find(RichTextBox textBoxToUse)
{
InitializeComponent();
_textBoxToUse = textBoxToUse;
}
private void button1_Click(object sender, EventArgs e)
{
_textBoxToUse.Select(5, 5);
}
}
Then, when the user clicks the "Find" button on that form, just go through that textbox and change the
SelectionStart
and
SelectionLength
properties to highlight the entire work.
You don't need to make it static...just pass it to the other form and anything that form does to it will happen to the original. Just make sure that you have changed the
RichTextBox
's
HideSelection
property to False so that even when it doesn't have the focus, the selection will show.