Results 1 to 5 of 5

Thread: [2005] number lines

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Maryland
    Posts
    182

    [2005] number lines

    can someone tell me how to number lines in a richtextbox just like vb?
    like have line 1 line 2 and so on?
    and how to make more numbers appear when the user hits enter?

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2005] number lines

    I believe the syntax editor in Visual Studio is actually a highly modified treeview. Doing this in an actual RichTextBox is a bit more difficult.

    I'd say use 2 RichTextBoxes and just add and remove numbers as needed from 1. Otherwise you're going to be either painting the RichTextBox yourself or doing some complex adding and removing numbers and adding/removing tabs to space everything apart.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Maryland
    Posts
    182

    Re: [2005] number lines

    o i thought it was textbox thats what it looks like.
    so how would i do this in a treeview?
    Last edited by jermaine; Jul 10th, 2006 at 11:41 PM. Reason: hello

  4. #4
    Addicted Member
    Join Date
    Jan 2002
    Location
    West Virginia
    Posts
    193

    Re: [2005] number lines

    Something you can do is split it using vbcrlf, add number to front of each line and then join it back together.

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [2005] number lines

    TextBox and RichTextBox have a lines property which you can loop through in order to loop through all lines of text that the control contains. In order to change this information, you can copy the info to a temp string array, modify the information, and then set the array back to the lines property of the control, like the example below. The below example should add sequential numbers to each line of text in a richtextbox control...
    VB Code:
    1. 'String array containing richtextbox information
    2.         Dim TextLines() As String = RichTextBox1.Lines
    3.         'loops through temp string array, adding numbers to each index
    4.         For I As Integer = 1 To TextLines.GetUpperBound(0) + 1
    5.             TextLines(I - 1) = I.ToString & " : " & TextLines(I - 1)
    6.         Next
    7.         'assign the new modified string array to the lines property of the control
    8.         RichTextBox1.Lines = TextLines
    Last edited by gigemboy; Jul 5th, 2006 at 12:08 PM. Reason: Removed counter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width