How can search for user selected text within a rich text box using a button?

Posted on 2005-05-04
Last Modified: 2010-04-23
I am trying to search for text from a rich text box that has already typed in another regular text box by pressing a button.  


I am trying alot but nothing seems to work.

Any suggestions?
Question by:sonicamps

    Author Comment

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

    LVL 85

    Accepted Solution

    You've almost got have to give the RTB focus to see the highlighted text:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim pos As Integer = RichTextBox1.Find(TextBox1.Text)
            If pos <> -1 Then
            End If
        End Sub

    OR...set the HideSelection() property of the RTB to false and your code will work.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    C# class property update 5 53
    Help file 1 28
    Need help error handling a windows service 2 25
    Starting to learn JAVA, 7 34
    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now