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?
Printable View
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?
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.
o i thought it was textbox thats what it looks like.
so how would i do this in a treeview?
Something you can do is split it using vbcrlf, add number to front of each line and then join it back together.
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:
'String array containing richtextbox information Dim TextLines() As String = RichTextBox1.Lines 'loops through temp string array, adding numbers to each index For I As Integer = 1 To TextLines.GetUpperBound(0) + 1 TextLines(I - 1) = I.ToString & " : " & TextLines(I - 1) Next 'assign the new modified string array to the lines property of the control RichTextBox1.Lines = TextLines