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. How to position cursor at some position in RichTextBox

How to position cursor at some position in RichTextBox

Scheduled Pinned Locked Moved C#
csharpwinformstoolshelptutorial
4 Posts 3 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.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position cursor to this character position ? RichTextBox does not have current position property.

    Andrus

    L S 2 Replies Last reply
    0
    • A AndrusM

      I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position cursor to this character position ? RichTextBox does not have current position property.

      Andrus

      L Offline
      L Offline
      LeandroABorges
      wrote on last edited by
      #2

      Hi Andrus, I got 2 options:

        richTextBox1.SelectionStart = 50;
        richTextBox1.SelectionLength = 0;
      
        richTextBox1.Select(60, 0);
      

      The second property/attribute that I´ve set 0 is the length of the selection, if you want to select some text, you can send the length of the selection, but if you don´t want to select, send 0 and then the cursor was positioned in the index.

      ----- LeandroAB

      S 1 Reply Last reply
      0
      • A AndrusM

        I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position cursor to this character position ? RichTextBox does not have current position property.

        Andrus

        S Offline
        S Offline
        Simon P Stevens
        wrote on last edited by
        #3

        Set the selection start to the character position you want, and the selection length to 0

        richTextBox1.SelectionStart = position;
        richTextBox1.SelectionLength = 0;

        Simon

        1 Reply Last reply
        0
        • L LeandroABorges

          Hi Andrus, I got 2 options:

            richTextBox1.SelectionStart = 50;
            richTextBox1.SelectionLength = 0;
          
            richTextBox1.Select(60, 0);
          

          The second property/attribute that I´ve set 0 is the length of the selection, if you want to select some text, you can send the length of the selection, but if you don´t want to select, send 0 and then the cursor was positioned in the index.

          ----- LeandroAB

          S Offline
          S Offline
          Simon P Stevens
          wrote on last edited by
          #4

          :laugh: Beat me to it. Nice one.

          Simon

          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