Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<b>:laugh:
I want to make my richtextbox static so that i can get the contents of my richtextbox on other form.
but my condition is that u might have seen the notepad in notepad when u click on find menustrip then find dialogbox appears and after clicking on Find next button the find method is called and the text is highlighted.
By using variable i will get the text of richtextbox on another form but i cant highlight the text of my richtextbox.
So pls help?
Thanks in advance if u provide the solution.</b>
Posted

1 solution

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...

C#
public FindForm(RichTextBox TextBoxToSearch)
{
   ...
}


Here's an example that I just tested:
C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900