Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Search and display text in richtextbox

Search and display text in richtextbox

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clatten
    wrote on last edited by
    #1

    I want to do a simple search function in a richtextbox. I have loaded a file and by using the Find method it's possible to find a text string, highlight the string and extract the line number, but how can I programatically scroll down to the line? private int findText(string searchText, int searchStart, int searchEnd) { int indexToText = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase); richTextBox1.SelectionColor = Color.Blue; int lineNo= richTextBox1.GetLineFromCharIndex(indexToText); return indexToText; }

    M 1 Reply Last reply
    0
    • C clatten

      I want to do a simple search function in a richtextbox. I have loaded a file and by using the Find method it's possible to find a text string, highlight the string and extract the line number, but how can I programatically scroll down to the line? private int findText(string searchText, int searchStart, int searchEnd) { int indexToText = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase); richTextBox1.SelectionColor = Color.Blue; int lineNo= richTextBox1.GetLineFromCharIndex(indexToText); return indexToText; }

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Why not just use the ScrollToCaret() method of RichTextBox? ;) Regards, mav

      C 1 Reply Last reply
      0
      • M mav northwind

        Why not just use the ScrollToCaret() method of RichTextBox? ;) Regards, mav

        C Offline
        C Offline
        clatten
        wrote on last edited by
        #3

        Embarrisingly enough I tried that first but discrded as not working. Just to find out that the control needed focus before it worked... So it was just to add richTextBox1.Focus(); richTextBox1.ScrollToCaret();

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups